diff --git a/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php b/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php index 916f542..5247dc9 100644 --- a/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php +++ b/app/Http/Controllers/Admin/APIs/Customer_API/RestaurantControllerApi.php @@ -69,4 +69,27 @@ class RestaurantControllerApi extends Controller return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } } + + /** + * Created By : Sayli Raut + * Created at : 28 May 2024 + * Use : To list of fav restaurant. + */ + public function listFavRestaurant() + { + try { + $token = readHeaderToken(); + + if ($token) { + $customerIamId = $token['sub']; + $response = $this->RestaurantApiServices->listFavRestaurant($customerIamId); + 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/CustomerFavouriteRestaurant.php b/app/Models/CustomerFavouriteRestaurant.php new file mode 100644 index 0000000..481c54a --- /dev/null +++ b/app/Models/CustomerFavouriteRestaurant.php @@ -0,0 +1,22 @@ +where('is_active', '1') ->get() ->toArray(); @@ -40,13 +42,45 @@ class RestaurantApiServices public function addToFavourite($customerIamId, $request) { try { - dd($request); + DB::beginTransaction(); + $restaurant = ManageRestaurant::where('short_id', $request->id)->first(); + if (!$restaurant) { + return jsonResponseWithErrorMessage(__('auth.restaurant_data_not_found'), 404); + } + $favRestaurant = new CustomerFavouriteRestaurant(); + $favRestaurant->principal_xid = $customerIamId; + $favRestaurant->restaurant_xid = $restaurant->id; + $favRestaurant->save(); + DB::commit(); + Log::info("details" . $favRestaurant); - - return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), 200); + return jsonResponseWithSuccessMessage(__('auth.data_updated_successfully'), 200); } catch (Exception $ex) { - Log::error('Restaurant Get service failed : ' . $ex->getMessage()); + DB::rollBack(); + Log::error('Favourite Restaurant service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + + public function listFavRestaurant($customerIamId) + { + try { + $list = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId)->get()->toArray(); + $customerFavouriteRestaurants = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId) + ->pluck('restaurant_xid') + ->toArray(); + + $restaurants = ManageRestaurant::whereIn('id', $customerFavouriteRestaurants)->get(); + + foreach ($restaurants as &$res) { + $res['image'] = ListingImageUrl('restaurant_images', $res['image']); + } + + 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); } } diff --git a/database/migrations/2024_05_30_120023_create_customer_favourite_restaurants_table.php b/database/migrations/2024_05_30_120023_create_customer_favourite_restaurants_table.php new file mode 100644 index 0000000..cb3ea26 --- /dev/null +++ b/database/migrations/2024_05_30_120023_create_customer_favourite_restaurants_table.php @@ -0,0 +1,34 @@ +id(); + $table->unsignedBigInteger('principal_xid'); + $table->foreign('principal_xid')->references('id')->on('iam_principal')->onDelete('cascade'); + $table->unsignedBigInteger('restaurant_xid'); + $table->foreign('restaurant_xid')->references('id')->on('manage_restaurants')->onDelete('cascade'); + $table->integer('created_by')->nullable(); + $table->integer('modified_by')->nullable(); + $table->softDeletes(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('customer_favourite_restaurants'); + } +}; diff --git a/routes/customer_api.php b/routes/customer_api.php index 3977481..e77d963 100644 --- a/routes/customer_api.php +++ b/routes/customer_api.php @@ -48,9 +48,7 @@ Route::post('/v1/delete_account', [CustomerControllerApi::class, 'destroyAccount Route::get('/v1/list-of-coordinates', [RestaurantControllerApi::class, 'getCoordinates']); Route::post('/v1/add-to-favourite', [RestaurantControllerApi::class, 'addToFavourite']); - - +Route::get('/v1/list-of-fav-restaurant', [RestaurantControllerApi::class, 'listFavRestaurant']); }); - });