From b6498fbba4819ffcf046f63bbd6a29b3d3fa15b4 Mon Sep 17 00:00:00 2001 From: sayliraut Date: Fri, 31 May 2024 17:25:56 +0530 Subject: [PATCH] change --- .../Customer_API/RestaurantControllerApi.php | 44 +++--------------- .../CustomerAPIs/RestaurantApiServices.php | 45 +++++-------------- routes/customer_api.php | 3 +- 3 files changed, 20 insertions(+), 72 deletions(-) diff --git a/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php b/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php index 9fe67a4..ffce122 100644 --- a/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php +++ b/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php @@ -25,15 +25,15 @@ class RestaurantControllerApi extends Controller public function getCoordinates() { try { - // $token = readHeaderToken(); + $token = readHeaderToken(); - // if ($token) { - // $customerIamId = $token['sub']; - $response = $this->RestaurantApiServices->getCoordinates(); + if ($token) { + $customerIamId = $token['sub']; + $response = $this->RestaurantApiServices->getCoordinates($customerIamId); return $response; - // } else { - // return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409); - // } + } else { + return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409); + } } catch (\Exception $e) { Log::error('Passport function failed: ' . $e->getMessage()); return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); @@ -116,34 +116,4 @@ class RestaurantControllerApi extends Controller } } - - /** - * Created By : Sayli Raut - * Created at : 31 May 2024 - * Use : To list of fav restaurant. - */ - // public function DetailRestaurant(Request $request) - // { - // try { - // $token = readHeaderToken(); - - // if ($token) { - // $customerIamId = $token['sub']; - // $validator = Validator::make($request->all(), [ - // 'ids' => 'required', - // ]); - - // if ($validator->fails()) { - // return jsonResponseWithErrorMessageApi($validator->errors()->first(), 400); - // } - // $response = $this->RestaurantApiServices->DetailRestaurant($customerIamId, $request); - // return $response; - // } else { - // return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409); - // } - // } catch (\Exception $e) { - // Log::error('Passport function failed: ' . $e->getMessage()); - // return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); - // } - // } } diff --git a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php index 572660b..1749bbb 100644 --- a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php +++ b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php @@ -13,10 +13,10 @@ use Illuminate\Support\Facades\Log; class RestaurantApiServices { - public function getCoordinates() + public function getCoordinates($customerIamId) { try { - $restaurant = ManageRestaurant::with('operatingHours')->select( + $restaurants = ManageRestaurant::with('operatingHours')->select( 'id', 'name', 'image', @@ -29,11 +29,16 @@ class RestaurantApiServices ->get() ->toArray(); - foreach ($restaurant as &$res) { - $res['image'] = ListingImageUrl('restaurant_images', $res['image']); + foreach ($restaurants as &$restaurant) { + $restaurant['image'] = ListingImageUrl('restaurant_images', $restaurant['image']); + + $isFavourite = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId) + ->where('restaurant_xid', $restaurant['id']) + ->exists(); + $restaurant['is_favourite'] = $isFavourite; } - return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $restaurant, 200); + return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $restaurants, 200); } catch (Exception $ex) { Log::error('Restaurant Get service failed : ' . $ex->getMessage()); return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); @@ -97,32 +102,6 @@ class RestaurantApiServices } - // public function DetailRestaurant($customerIamId, $request) - // { - // try { - // $rawIds = $request->input('ids'); - // Log::info('Raw ids: ' . $rawIds); - - // $ids = json_decode($rawIds, true); - - // if (json_last_error() !== JSON_ERROR_NONE) { - // $rawIds = trim($rawIds, '[]'); - // $ids = array_map('trim', explode(',', $rawIds)); - - // } - // $restaurants = ManageRestaurant::with('operatingHours')->whereIn('short_id', $ids)->get(); - // foreach ($restaurants as &$res) { - // $res['image'] = ListingImageUrl('restaurant_images', $res['image']); - // } - // return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $restaurants, 200); - // } catch (\Exception $ex) { - // Log::error('DetailRestaurant service failed: ' . $ex->getMessage()); - // return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); - // } - // } - - - public function DetailRestaurant($customerIamId, $id) { try { @@ -130,8 +109,8 @@ class RestaurantApiServices if ($rest) { $rest->image = ListingImageUrl('restaurant_images', $rest->image); $isFavourite = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId) - ->where('restaurant_xid', $rest->id) - ->exists(); + ->where('restaurant_xid', $rest->id) + ->exists(); $rest->is_favourite = $isFavourite; } if (!$rest) { diff --git a/routes/customer_api.php b/routes/customer_api.php index 5093351..70e643c 100644 --- a/routes/customer_api.php +++ b/routes/customer_api.php @@ -9,7 +9,6 @@ use App\Http\Controllers\Admin\APIs\Customer_API\RestaurantControllerApi; use Illuminate\Support\Facades\Route; -Route::get('/v1/list-of-coordinates', [RestaurantControllerApi::class, 'getCoordinates']); Route::middleware(['customerApiBasicAuth'])->group(function () { @@ -50,7 +49,7 @@ Route::middleware(['customerApiBasicAuth'])->group(function () { Route::get('/v1/detail-of-restaurant/{id}', [RestaurantControllerApi::class, 'DetailRestaurant']); Route::post('/v1/add-to-favourite', [RestaurantControllerApi::class, 'addToFavourite']); Route::get('/v1/list-of-fav-restaurant', [RestaurantControllerApi::class, 'listFavRestaurant']); - // Route::post('/v1/detail-of-restaurant', [RestaurantControllerApi::class, 'DetailRestaurant']); + Route::get('/v1/list-of-coordinates', [RestaurantControllerApi::class, 'getCoordinates']); //*******************************************************notification********************************************************