From 051bc0577bebe37aa62a08ffeb031a623d88d8a3 Mon Sep 17 00:00:00 2001 From: sayliraut Date: Fri, 31 May 2024 13:24:45 +0530 Subject: [PATCH] change --- .../Customer_API/RestaurantControllerApi.php | 1 + .../CustomerAPIs/RestaurantApiServices.php | 20 ++++++++++++++----- resources/lang/en/auth.php | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php b/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php index ba1d39e..fb476bf 100644 --- a/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php +++ b/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php @@ -47,6 +47,7 @@ class RestaurantControllerApi extends Controller */ public function addToFavourite(Request $request) { + dd("hii"); try { $token = readHeaderToken(); diff --git a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php index 8506835..d915994 100644 --- a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php +++ b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php @@ -48,22 +48,32 @@ class RestaurantApiServices if (!$restaurant) { return jsonResponseWithErrorMessage(__('auth.restaurant_data_not_found'), 404); } + + $existingFavourite = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId) + ->where('restaurant_xid', $restaurant->id) + ->first(); + + if ($existingFavourite) { + return jsonResponseWithErrorMessage(__('auth.restaurant_already_favourite'), 409); + } + $favRestaurant = new CustomerFavouriteRestaurant(); - $favRestaurant->principal_xid = $customerIamId; - $favRestaurant->restaurant_xid = $restaurant->id; + $favRestaurant->principal_xid = $customerIamId; + $favRestaurant->restaurant_xid = $restaurant->id; $favRestaurant->save(); + DB::commit(); - Log::info("details" . $favRestaurant); return jsonResponseWithSuccessMessage(__('auth.data_updated_successfully'), 200); - } catch (Exception $ex) { + } catch (\Exception $ex) { DB::rollBack(); - Log::error('Favourite Restaurant service failed : ' . $ex->getMessage()); + Log::error('Favourite Restaurant service failed: ' . $ex->getMessage()); return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); } } + public function listFavRestaurant($customerIamId) { try { diff --git a/resources/lang/en/auth.php b/resources/lang/en/auth.php index 2f88e3e..ad18494 100644 --- a/resources/lang/en/auth.php +++ b/resources/lang/en/auth.php @@ -104,5 +104,6 @@ return [ 'otp_expired_invalid' => 'Invalid OTP or expired.', 'legally_21' => 'You are legally over the age of 21. Proceed to the next page.', 'not_legally_21' => 'Sorry, you are not legally over the age of 21. Exit the page.', + 'restaurant_already_favourite' => 'restaurant already in favourite list' ];