diff --git a/app/Http/Controllers/Admin/APIs/RestaurantApi/RestAuthApiController.php b/app/Http/Controllers/Admin/APIs/RestaurantApi/RestAuthApiController.php index 2090751..7bf8dbd 100644 --- a/app/Http/Controllers/Admin/APIs/RestaurantApi/RestAuthApiController.php +++ b/app/Http/Controllers/Admin/APIs/RestaurantApi/RestAuthApiController.php @@ -1,6 +1,7 @@ RestAuthApiService->searchRest($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/RestaurantService/RestAuthApiService.php b/app/Services/APIs/RestaurantService/RestAuthApiService.php index 472f99e..f1a2400 100644 --- a/app/Services/APIs/RestaurantService/RestAuthApiService.php +++ b/app/Services/APIs/RestaurantService/RestAuthApiService.php @@ -25,7 +25,7 @@ class RestAuthApiService public function viewresyaurant() { try { - $data = ManageRestaurant::select('id', 'name','description','restaurant_id','address','image','bio','try_on_1','try_on_2','try_on_3','try_on_4','exclusion','latitude','longtitude')->where('is_active', 1)->get()->toArray(); + $data = ManageRestaurant::select('id', 'name', 'description', 'restaurant_id', 'address', 'image', 'bio', 'try_on_1', 'try_on_2', 'try_on_3', 'try_on_4', 'exclusion', 'latitude', 'longtitude')->where('is_active', 1)->get()->toArray(); return $data; } catch (Exception $ex) { DB::rollBack(); @@ -226,32 +226,36 @@ class RestAuthApiService if (!$iamPrincipal) { $errors[] = __('auth.failed_to_verify_otp'); return jsonResponseWithErrorMessageApi( - $errors,403 - ); + $errors, + 403 + ); } // Check if the provided OTP matches the stored OTP if ($iamPrincipal->otp_code !== $request->otp) { $errors[] = __('auth.invalid_otp'); return jsonResponseWithErrorMessageApi( - $errors,403 - ); + $errors, + 403 + ); } // Check if the OTP is still valid if (Carbon::now()->gt($iamPrincipal->valid_till)) { $errors[] = __('auth.otp_expired'); return jsonResponseWithErrorMessageApi( - $errors,403 - ); + $errors, + 403 + ); } // Check if the OTP has already been used if ($iamPrincipal->is_used === 1) { $errors[] = __('auth.otp_already_used'); return jsonResponseWithErrorMessageApi( - $errors,403 - ); + $errors, + 403 + ); } @@ -373,4 +377,27 @@ class RestAuthApiService } return $otp; } + + + + public function searchRest($request) + { + try { + $searchQuery = $request->input('search_data'); + + $query = ManageRestaurant::select('id', 'name')->where('is_active', 1); + + if ($searchQuery) { + $query->where(function ($q) use ($searchQuery) { + $q->where('name', 'like', '%' . $searchQuery . '%') + ->orWhere('address', '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/restaurant_api.php b/routes/restaurant_api.php index d68ad2f..14ab2c4 100644 --- a/routes/restaurant_api.php +++ b/routes/restaurant_api.php @@ -18,6 +18,8 @@ Route::middleware(['restaurantApiBasicAuth'])->group(function () { Route::post('/v1/rest-verify-otp', [RestAuthApiController::class, 'restVerifyOTP']); Route::post('/v1/rest-change-password', [RestAuthApiController::class, 'restChangePassword']); Route::post('/v1/rest-resend-otp', [RestAuthApiController::class, 'restResendOtp']); + Route::post('/v1/search-rest', [RestAuthApiController::class, 'searchRest']); + Route::group(['middleware' => ['restaurant.jwt.verify']], function () { // //*******************************************************Restaurant profile********************************************************