diff --git a/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php b/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php index a280ace..ba1d39e 100644 --- a/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php +++ b/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php @@ -19,7 +19,7 @@ class RestaurantControllerApi extends Controller /** * Created By : Sayli Raut - * Created at : 28 May 2024 + * Created at : 30 May 2024 * Use : To get restaurant. */ public function getCoordinates() @@ -42,7 +42,7 @@ class RestaurantControllerApi extends Controller /** * Created By : Sayli Raut - * Created at : 28 May 2024 + * Created at : 30 May 2024 * Use : To add favourite. */ public function addToFavourite(Request $request) @@ -72,7 +72,7 @@ class RestaurantControllerApi extends Controller /** * Created By : Sayli Raut - * Created at : 28 May 2024 + * Created at : 30 May 2024 * Use : To list of fav restaurant. */ public function listFavRestaurant() @@ -92,4 +92,34 @@ class RestaurantControllerApi extends Controller return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } } + + /** + * 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/Models/ManageRestaurant.php b/app/Models/ManageRestaurant.php index 924e24e..9b5dcc7 100644 --- a/app/Models/ManageRestaurant.php +++ b/app/Models/ManageRestaurant.php @@ -42,6 +42,10 @@ class ManageRestaurant extends Model return $shortId; } + public function operatingHours() + { + return $this->hasMany(OperatingHour::class,'manage_restaurant_xid', 'id'); + } public function state() { diff --git a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php index 228af4a..8506835 100644 --- a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php +++ b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php @@ -72,16 +72,42 @@ class RestaurantApiServices ->pluck('restaurant_xid') ->toArray(); - $restaurants = ManageRestaurant::whereIn('id', $customerFavouriteRestaurants)->get(); + $restaurants = ManageRestaurant::whereIn('id', $customerFavouriteRestaurants)->get(); - foreach ($restaurants as &$res) { - $res['image'] = ListingImageUrl('restaurant_images', $res['image']); - } + foreach ($restaurants as &$res) { + $res['image'] = ListingImageUrl('restaurant_images', $res['image']); + } - return jsonResponseWithSuccessMessage(__('auth.data_updated_successfully'), $restaurants ,200); + return jsonResponseWithSuccessMessage(__('auth.data_updated_successfully'), $restaurants, 200); } catch (Exception $ex) { Log::error('List of Favourite Restaurant service failed : ' . $ex->getMessage()); return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); } } + + + 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::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); + } + } + } diff --git a/routes/customer_api.php b/routes/customer_api.php index 78d7635..60ddd2e 100644 --- a/routes/customer_api.php +++ b/routes/customer_api.php @@ -49,6 +49,8 @@ Route::post('/v1/delete_account', [CustomerControllerApi::class, 'destroyAccount 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']); + }); });