From 47ea603c1010765c5ec329d657c829ca7c4921c1 Mon Sep 17 00:00:00 2001 From: sayliraut Date: Wed, 19 Jun 2024 17:26:37 +0530 Subject: [PATCH] search state API --- .../APIs/Customer_API/AuthController.php | 16 +++++++++++++++ .../APIs/CustomerAPIs/AuthServices.php | 20 +++++++++++++++++++ routes/customer_api.php | 2 ++ 3 files changed, 38 insertions(+) diff --git a/app/Http/Controllers/Admin/APIs/Customer_API/AuthController.php b/app/Http/Controllers/Admin/APIs/Customer_API/AuthController.php index 174edb5..3ee8478 100644 --- a/app/Http/Controllers/Admin/APIs/Customer_API/AuthController.php +++ b/app/Http/Controllers/Admin/APIs/Customer_API/AuthController.php @@ -269,4 +269,20 @@ class AuthController extends Controller return response()->json(__('something_went_wrong'), 500); } } + + /** + * Created By : Sayli Raut + * Created at : 19 June 2024 + * Use : Search State. + */ + public function searchState(Request $request) + { + try { + return $this->AuthServices->searchState($request); + } catch (\Exception $ex) { + Log::error("Login API Failed: " . $ex->getMessage()); + return jsonResponseWithErrorMessage(__('error_message.something_went_wrong'), 500); + } + } + } diff --git a/app/Services/APIs/CustomerAPIs/AuthServices.php b/app/Services/APIs/CustomerAPIs/AuthServices.php index 6ceebb1..d68626b 100644 --- a/app/Services/APIs/CustomerAPIs/AuthServices.php +++ b/app/Services/APIs/CustomerAPIs/AuthServices.php @@ -310,4 +310,24 @@ class AuthServices return jsonResponseWithErrorMessageApi(__('auth.authentication_failed'), 403); } } + + public function searchState($request) + { + try { + $searchQuery = $request->input('search_data'); + + $query = ManageState::select('id', 'name')->where('is_active', 1); + + if ($searchQuery) { + $query->where(function ($q) use ($searchQuery) { + $q->where('name', 'like', '%' . $searchQuery . '%'); + }); + } + $restaurants = $query->get(); + return jsonResponseWithSuccessMessageApi(__('auth.data_fetched_successfully'), $restaurants, 200); + } catch (\Exception $e) { + Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage()); + return response()->json(__('something_went_wrong'), 500); + } + } } diff --git a/routes/customer_api.php b/routes/customer_api.php index bde5f40..8133a90 100644 --- a/routes/customer_api.php +++ b/routes/customer_api.php @@ -24,6 +24,8 @@ Route::middleware(['customerApiBasicAuth'])->group(function () { Route::post('/v1/password/verify-otp', [AuthController::class, 'verifyOtpForgotPassword']); Route::post('/v1/change-password', [AuthController::class, 'changePassword']); Route::post('/v1/resend-otp', [AuthController::class, 'resendOtp']); + Route::post('/v1/search-state', [AuthController::class, 'searchState']); + Route::group(['middleware' => ['customer.jwt.verify']], function () {