diff --git a/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php b/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php index fa61c16..19b8990 100644 --- a/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php +++ b/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php @@ -148,4 +148,26 @@ class RestaurantControllerApi extends Controller return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } } + + + /** + * Created By : Sayli Raut + * Created at : 04 June 2024 + * Use : To search from favourite. + */ + public function searchFromFavourite(Request $request) + { + try { + $token = readHeaderToken(); + if ($token) { + $customerIamId = $token['sub']; + return $this->RestaurantApiServices->searchFromFavourite($customerIamId, $request); + } else { + return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409); + } + } catch (\Exception $e) { + Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]); + return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); + } + } } diff --git a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php index c4fddf8..bc02465 100644 --- a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php +++ b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php @@ -151,4 +151,43 @@ class RestaurantApiServices return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); } } + + + public function searchFromFavourite($customerIamId, $request) + { + try { + $customerFavouriteRestaurants = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId) + ->pluck('restaurant_xid') + ->toArray(); + + $restaurantsQuery = ManageRestaurant::with('operatingHours') + ->where('is_active', '1') + ->whereIn('id', $customerFavouriteRestaurants); + + $searchData = $request->input('search_data'); + + if (!empty($searchData)) { + $restaurantsQuery->where(function ($query) use ($searchData) { + $query->where('name', 'like', "%$searchData%") + ->orWhere('description', 'like', "%$searchData%") + ->orWhere('address', 'like', "%$searchData%"); + }); + } + + $restaurants = $restaurantsQuery->get(); + foreach ($restaurants as &$res) { + $res['image'] = ListingImageUrl('restaurant_images', $res['image']); + } + + + return jsonResponseWithSuccessMessageApi(__('auth.passport_search'), $restaurants, 200); + + } catch (Exception $ex) { + Log::error('Search from favourite restaurant service failed: ' . $ex->getMessage()); + return response()->json([ + 'message' => __('auth.something_went_wrong') + ], 500); + } + } + } diff --git a/routes/customer_api.php b/routes/customer_api.php index c5f00b4..229c5ea 100644 --- a/routes/customer_api.php +++ b/routes/customer_api.php @@ -51,6 +51,8 @@ Route::middleware(['customerApiBasicAuth'])->group(function () { Route::get('/v1/list-of-fav-restaurant', [RestaurantControllerApi::class, 'listFavRestaurant']); Route::get('/v1/list-of-coordinates', [RestaurantControllerApi::class, 'getCoordinates']); Route::post('/v1/remove-from-favourite', [RestaurantControllerApi::class, 'removeFromFavourite']); + Route::post('/v1/search-from-favourite', [RestaurantControllerApi::class, 'searchFromFavourite']); +