bookingServices = $bookingServices; parent::__construct(); } public function index(Request $request) { $lists = $this->bookingServices->index($request); if ($lists instanceof \Illuminate\Pagination\LengthAwarePaginator){ return (new BookingListResource($lists))->additional([ 'totalPage' => $lists->total(), 'lastPage' => $lists->lastPage(), 'currentPage' => $lists->currentPage(), 'perPage' => (int)$lists->perPage(), ]); } return (new BookingListResource($lists)); } public function show(Request $request, $bookingId) { try { $entity = $this->bookingServices->show($bookingId); return $this->responseJson('success', Response::HTTP_OK, new BookingDetailResource($entity)); } catch (\Exception $e) { return $this->responseJson('fail', Response::HTTP_INTERNAL_SERVER_ERROR, []); } } public function update(Request $request, $bookingId) { $info = $request->only([ 'id', "checkin_at", "checkout_at", "number_guests", "status", "customer_id" ]); DB::beginTransaction(); try { $entity = $this->bookingServices->save($info); DB::commit(); return $this->responseJson('success', Response::HTTP_OK, new BookingDetailResource($entity)); } catch (\Exception $e) { DB::rollback(); return $this->responseJson('fail', Response::HTTP_INTERNAL_SERVER_ERROR, []); } } public function store(Request $request) { // todo : neu that bai tra ve ly do that bai $info = $request->only([ 'packets', 'room', 'checkout_at', 'checkin_at', 'guests', 'payment.payment_method', 'payment.payment_date', 'payment.description', 'payment.payment_amount', 'payment.address', 'payment.email', 'payment.city', 'payment.state', 'payment.post_code', ]); DB::beginTransaction(); try { $entity = $this->bookingServices->makeCheckout($info); DB::commit(); return $this->responseJson('success', Response::HTTP_OK, new BookingDetailResource($entity)); } catch (\Exception $e) { DB::rollback(); return $this->responseJson($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR, ["status" => 4]); } } }