@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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']);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user