userServices = $userServices; parent::__construct(); } public function indexWishlist(Request $request) { $request['loadRelation'] = [ "wishlists", ]; $lists = $this->userServices->getAllWishlists($request); if ($lists instanceof \Illuminate\Pagination\LengthAwarePaginator){ return (new UserListResource($lists))->additional([ 'totalPage' => $lists->total(), 'lastPage' => $lists->lastPage(), 'currentPage' => $lists->currentPage(), 'perPage' => (int)$lists->perPage(), ]); } return (new UserListResource($lists)); } public function updateWishlist(Request $request,$customerId) { $info = $request->only([ "room_types", "id", ]); DB::beginTransaction(); try { $entity = $this->userServices->saveWishlists($request,$info); DB::commit(); return $this->responseJson('success', Response::HTTP_OK, new UserDetailResource($entity)); } catch (\Exception $e) { DB::rollback(); return $this->responseJson('fail', Response::HTTP_INTERNAL_SERVER_ERROR, []); } } public function index(Request $request) { $request['loadRelation'] = [ "bookings", ]; $lists = $this->userServices->index($request); if ($lists instanceof \Illuminate\Pagination\LengthAwarePaginator){ return (new UserListResource($lists))->additional([ 'totalPage' => $lists->total(), 'lastPage' => $lists->lastPage(), 'currentPage' => $lists->currentPage(), 'perPage' => (int)$lists->perPage(), ]); } return (new UserListResource($lists)); } public function update(Request $request,$id) { $validator = Validator::make($request->all(), [ 'first_name' => 'required|string|between:2,100', 'last_name' => 'required|string|between:2,100', 'phone' => 'required|string|max:20|between:6,20', ]); if ($validator->fails()) { return $this->responseErrorJson("fail", Response::HTTP_CONFLICT, $validator->errors()->first()); } $info = $request->only([ "email", "first_name", "last_name", "phone", "birthday", "national" ]); $info['id'] = $id; DB::beginTransaction(); try { $entity = $this->userServices->save($info); DB::commit(); return $this->responseJson('success', Response::HTTP_OK, new UserDetailResource($entity)); } catch (\Exception $e) { DB::rollback(); return $this->responseJson('fail', Response::HTTP_INTERNAL_SERVER_ERROR, []); } } }