From b0aff64ad35f6cc188dc4fdcf969cfe169d1a4a1 Mon Sep 17 00:00:00 2001 From: sayaliparab Date: Wed, 29 May 2024 17:13:40 +0530 Subject: [PATCH] Restapi --- .../RestaurantApi/RestAuthApiController.php | 69 ------- .../RestaurantApi/RestAuthApiController.php | 186 ++++++++++++++++++ .../Controllers/Admin/DashboardController.php | 1 + .../Admin/ManageProfileController.php | 9 +- .../RestaurantService/RestAuthApiService.php | 98 ++++----- .../RestaurantApiService.php | 4 +- resources/views/Admin/dashboard.blade.php | 2 +- routes/restaurant_api.php | 5 +- 8 files changed, 244 insertions(+), 130 deletions(-) delete mode 100644 app/Http/Controllers/APIs/RestaurantApi/RestAuthApiController.php create mode 100644 app/Http/Controllers/Admin/APIs/RestaurantApi/RestAuthApiController.php diff --git a/app/Http/Controllers/APIs/RestaurantApi/RestAuthApiController.php b/app/Http/Controllers/APIs/RestaurantApi/RestAuthApiController.php deleted file mode 100644 index fcc87a3..0000000 --- a/app/Http/Controllers/APIs/RestaurantApi/RestAuthApiController.php +++ /dev/null @@ -1,69 +0,0 @@ -RestAuthApiService = $RestAuthApiService; - } - - public function viewresyaurant() - { - try { - $response = $this->RestAuthApiService->viewresyaurant(); - return jsonResponseWithSuccessMessageApi(__('success.data_fetched_successfully'), $response, 200); - } catch (\Exception $e) { - Log::error('FAW get data controller function failed: ' . $e->getMessage()); - return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); - } - } - - public function restRegister(Request $request) - { - try { - $validator = Validator::make($request->all(), [ - 'first_name' => 'required|string|min:2|max:100', - 'last_name' => 'required|string|min:2|max:100', - 'role' => 'required|string|min:2|max:100', - 'restaurant_xid' => 'required', - 'date_of_birth' => 'required|date', - 'email_address' => [ - 'required', - 'string', - 'email', - 'max:100', - Rule::unique('iam_principal')->where(function ($query) { - return $query->where('principal_type_xid', 4)->whereNull('deleted_at'); - }), - ], - 'phone_number' => 'required|min:10', - ]); - - if ($validator->fails()) { - $validationErrors = $validator->errors()->all(); - Log::error("Registration validation error: " . implode(", ", $validationErrors)); - return jsonResponseWithErrorMessageApi($validationErrors, 403); - } - return $this->RestAuthApiService->restRegister($request); - } catch (\Exception $ex) { - Log::error("Registration API Failed: " . $ex->getMessage()); - return jsonResponseWithErrorMessage(__('error_message.something_went_wrong'), 500); - } - } - -} diff --git a/app/Http/Controllers/Admin/APIs/RestaurantApi/RestAuthApiController.php b/app/Http/Controllers/Admin/APIs/RestaurantApi/RestAuthApiController.php new file mode 100644 index 0000000..353e38a --- /dev/null +++ b/app/Http/Controllers/Admin/APIs/RestaurantApi/RestAuthApiController.php @@ -0,0 +1,186 @@ +RestAuthApiService = $RestAuthApiService; + } + + public function viewresyaurant() + { + try { + $response = $this->RestAuthApiService->viewresyaurant(); + // dd( $response); + return jsonResponseWithSuccessMessageApi(__('success.data_fetched_successfully'), $response, 200); + } catch (\Exception $e) { + Log::error('FAW get data controller function failed: ' . $e->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + public function restRegister(Request $request) + { + try { + $validator = Validator::make($request->all(), [ + 'first_name' => 'required|string|min:2|max:100', + 'last_name' => 'required|string|min:2|max:100', + 'role' => 'required|string|min:2|max:100', + 'restaurant_xid' => 'required', + 'date_of_birth' => 'required|date', + 'email_address' => [ + 'required', + 'string', + 'email', + 'max:100', + Rule::unique('iam_principal')->where(function ($query) { + return $query->where('principal_type_xid', 4)->whereNull('deleted_at'); + }), + ], + 'phone_number' => 'required|min:10', + ]); + + if ($validator->fails()) { + $validationErrors = $validator->errors()->all(); + Log::error("Registration validation error: " . implode(", ", $validationErrors)); + return jsonResponseWithErrorMessageApi($validationErrors, 403); + } + return $this->RestAuthApiService->restRegister($request); + } catch (\Exception $ex) { + Log::error("Registration API Failed: " . $ex->getMessage()); + return jsonResponseWithErrorMessage(__('error_message.something_went_wrong'), 500); + } + } + + public function login(Request $request) + { + try { + $validator = Validator::make($request->all(), [ + 'email_address' => 'required|string|email', + 'password' => 'required|string|min:6', + ]); + + if ($validator->fails()) { + $validationErrors = $validator->errors()->all(); + Log::error("Login validation error: " . implode(", ", $validationErrors)); + return jsonResponseWithErrorMessageApi($validationErrors, 403); + } + return $this->RestAuthApiService->login($request); + } catch (\Exception $ex) { + Log::error("Login API Failed: " . $ex->getMessage()); + return jsonResponseWithErrorMessage(__('error_message.something_went_wrong'), 500); + } + } + public function restForgotPassword(Request $request) + { + try { + $validator = Validator::make($request->all(), [ + 'email_address' => [ + 'required', + 'string', + 'email', + function ($attribute, $value, $fail) { + $existingUser = IamPrincipal::where('email_address', $value)->where('principal_type_xid', 4)->whereNull('deleted_at')->exists(); + if (!$existingUser) { + $fail('The selected email address is invalid.'); + } + }, + ], + ]); + + if ($validator->fails()) { + $validationErrors = $validator->errors()->all(); + Log::error("Forgot password validation error: " . implode(", ", $validationErrors)); + + return jsonResponseWithErrorMessageApi($validationErrors, 403); + } + return $this->RestAuthApiService->restForgotPassword($request); + } catch (\Exception $ex) { + Log::error("Forgot password API Failed: " . $ex->getMessage()); + return jsonResponseWithErrorMessage(__('error_message.something_went_wrong'), 500); + } + } + + public function restVerifyOTP(Request $request) + { + try { + $validator = Validator::make($request->all(), [ + 'email_address' => [ + 'required', + 'string', + 'email', + function ($attribute, $value, $fail) { + $existingUser = IamPrincipal::where('email_address', $value)->where('principal_type_xid', 4)->whereNull('deleted_at')->exists(); + if (!$existingUser) { + $fail('The selected email address is invalid.'); + } + }, + ], + 'otp' => 'required', + ]); + + if ($validator->fails()) { + $validationErrors = $validator->errors()->all(); + Log::error("Forgot password validation error: " . implode(", ", $validationErrors)); + return jsonResponseWithErrorMessageApi($validationErrors, 403); + } + return $this->RestAuthApiService->restVerifyOTP($request); + } catch (\Exception $ex) { + Log::error("Verify password API Failed: " . $ex->getMessage()); + return jsonResponseWithErrorMessage(__('error_message.something_went_wrong'), 500); + } + } + public function restChangePassword(Request $request) + { + try { + $validator = Validator::make($request->all(), [ + 'iam_principal_xid' => 'required|exists:iam_principal,id', + 'password' => 'required|confirmed', + ]); + if ($validator->fails()) { + $validationErrors = $validator->errors()->all(); + Log::error("Forgot password validation error: " . implode(", ", $validationErrors)); + return jsonResponseWithErrorMessageApi($validationErrors, 403); + } + $response = $this->RestAuthApiService->restChangePassword($request); + return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $response, 200); + } catch (\Exception $ex) { + Log::error("Change password API Failed: " . $ex->getMessage()); + return jsonResponseWithErrorMessage(__('error_message.something_went_wrong'), 500); + } + } + public function restResendOtp(Request $request) + { + try { + $validator = Validator::make($request->all(), [ + 'iam_principal_xid' => 'required|exists:iam_principal,id', + 'otp_purpose' => 'required' + ]); + if ($validator->fails()) { + $validationErrors = $validator->errors()->all(); + Log::error("Forgot password validation error: " . implode(", ", $validationErrors)); + return jsonResponseWithErrorMessageApi($validationErrors, 403); + } + return $this->RestAuthApiService->restResendOtp($request); + } catch (\Exception $ex) { + Log::error("Resend otp API Failed: " . $ex->getMessage()); + return jsonResponseWithErrorMessage(__('error_message.something_went_wrong'), 500); + } + } +} diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index dc3adc9..435fe44 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -83,6 +83,7 @@ class DashboardController extends Controller ->orderBy(DB::raw("MONTH(created_at)")) ->pluck('count', 'month') ->toArray(); + // dd($dataMonthlyWithType3); $dataMonthlyWithType4 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month")) ->whereIn('principal_type_xid', [4]) diff --git a/app/Http/Controllers/Admin/ManageProfileController.php b/app/Http/Controllers/Admin/ManageProfileController.php index 8e06fc6..54ca332 100644 --- a/app/Http/Controllers/Admin/ManageProfileController.php +++ b/app/Http/Controllers/Admin/ManageProfileController.php @@ -14,14 +14,7 @@ use Illuminate\Support\Facades\Auth; class ManageProfileController extends Controller { - // public function index(){ - - // // $get_user = Auth::guard('admin')->user(); - // // dd($get_user); - // // $user = IamPrincipal::find($get_user->id); - // $user = IamPrincipal::find(1); - // return view('Admin.pages.manage_profile.manage_profile',compact('user')); - // } + public function index() { $get_user = Auth::guard('admin')->user(); diff --git a/app/Services/APIs/RestaurantService/RestAuthApiService.php b/app/Services/APIs/RestaurantService/RestAuthApiService.php index 9529edb..aa444d8 100644 --- a/app/Services/APIs/RestaurantService/RestAuthApiService.php +++ b/app/Services/APIs/RestaurantService/RestAuthApiService.php @@ -2,8 +2,8 @@ namespace App\Services\APIs\RestaurantService; -use App\Models\admin\ManageRestaurant; -use App\Models\admin\ManageVoucherModel; +use App\Models\ManageRestaurant; +use App\Models\ManageVoucherModel; use Exception; use Illuminate\Support\Facades\Auth; use App\Models\IamPrincipal; @@ -23,7 +23,7 @@ class RestAuthApiService public function viewresyaurant() { try { - $data = ManageVoucherModel::select('id', 'coupon_name')->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(); @@ -33,59 +33,59 @@ class RestAuthApiService } - public function restRegister($request) - { - try { - DB::beginTransaction(); - $restaurantId = $request->input('restaurant_xid'); + // public function restRegister($request) + // { + // try { + // DB::beginTransaction(); + // $restaurantId = $request->input('restaurant_xid'); - // Fetch the restaurant details based on the selected restaurantId - $selectedRestaurant = ManageVoucherModel::find($restaurantId); + // // Fetch the restaurant details based on the selected restaurantId + // $selectedRestaurant = ManageVoucherModel::find($restaurantId); - if (!$selectedRestaurant) { - return jsonResponseWithErrorMessageApi(__('auth.restaurant_data_not_found'), 403); - } + // if (!$selectedRestaurant) { + // return jsonResponseWithErrorMessageApi(__('auth.restaurant_data_not_found'), 403); + // } - // Create a new restaurant user record - $restaurantuser = IamPrincipal::create([ - 'one_signal_player_id' => $request->one_signal_player_id, - 'first_name' => $request->first_name, - 'last_name' => $request->last_name, - 'email_address' => $request->email_address, - // 'password' => Hash::make('Cheers@123'), - 'principal_type_xid' => 4, //4 for restaurant - 'principal_source_xid' => 2, //2 for mobile - 'phone_number' => $request->phone_number, - 'date_of_birth' => $request->date_of_birth, - 'is_active' => '0', - ]); + // // Create a new restaurant user record + // $restaurantuser = IamPrincipal::create([ + // 'one_signal_player_id' => $request->one_signal_player_id, + // 'first_name' => $request->first_name, + // 'last_name' => $request->last_name, + // 'email_address' => $request->email_address, + // // 'password' => Hash::make('Cheers@123'), + // 'principal_type_xid' => 4, //4 for restaurant + // 'principal_source_xid' => 2, //2 for mobile + // 'phone_number' => $request->phone_number, + // 'date_of_birth' => $request->date_of_birth, + // 'is_active' => '0', + // ]); - $restaurantUserRole = IamPrincipalRestaurantRole::create([ - 'principal_xid' => $restaurantuser->id, - 'role' => $request->role, - 'restaurant_xid' => $restaurantId, - ]); + // $restaurantUserRole = IamPrincipalRestaurantRole::create([ + // 'principal_xid' => $restaurantuser->id, + // 'role' => $request->role, + // 'restaurant_xid' => $restaurantId, + // ]); - DB::commit(); + // DB::commit(); - // $token = auth()->login($restaurantuser); + // // $token = auth()->login($restaurantuser); - // Return response with user details, access token, and status - $response = [ - 'user' => $restaurantuser, - // 'restaurant_details' => $restaurantId, - // 'access_token' => $token, - 'token_type' => 'bearer', - 'status' => 'Your request has been sent. Kindly check your email.' - ]; - return jsonResponseWithSuccessMessage(__('auth.Rest_user_created'), $response, 200); - } catch (QueryException $e) { - // Rollback transaction in case of an error - DB::rollBack(); - Log::error('Restaurant Registration Failed ' . $e->getMessage()); - return jsonResponseWithErrorMessageApi(__('auth.authentication_failed'), 403); - } - } + // // Return response with user details, access token, and status + // $response = [ + // 'user' => $restaurantuser, + // // 'restaurant_details' => $restaurantId, + // // 'access_token' => $token, + // 'token_type' => 'bearer', + // 'status' => 'Your request has been sent. Kindly check your email.' + // ]; + // return jsonResponseWithSuccessMessage(__('auth.Rest_user_created'), $response, 200); + // } catch (QueryException $e) { + // // Rollback transaction in case of an error + // DB::rollBack(); + // Log::error('Restaurant Registration Failed ' . $e->getMessage()); + // return jsonResponseWithErrorMessageApi(__('auth.authentication_failed'), 403); + // } + // } public function login($request) diff --git a/app/Services/APIs/RestaurantService/RestaurantApiService.php b/app/Services/APIs/RestaurantService/RestaurantApiService.php index 4ff9e9a..9310d04 100644 --- a/app/Services/APIs/RestaurantService/RestaurantApiService.php +++ b/app/Services/APIs/RestaurantService/RestaurantApiService.php @@ -1,8 +1,8 @@
Locations
- +
diff --git a/routes/restaurant_api.php b/routes/restaurant_api.php index a640150..c3f51b4 100644 --- a/routes/restaurant_api.php +++ b/routes/restaurant_api.php @@ -11,7 +11,10 @@ use Illuminate\Support\Facades\Route; Route::middleware(['restaurantApiBasicAuth'])->group(function () { // Define your routes here - Route::get('/v1/list-restaurant', [RestAuthApiController::class, 'viewresyaurant']); + // Route::get('/v1/list-restaurant', [RestAuthApiController::class, 'viewresyaurant']); + // In routes/api.php +Route::get('/v1/list-restaurant', [RestAuthApiController::class, 'viewResyaurant']); + Route::post('/v1/rest-register', [RestAuthApiController::class, 'restRegister']); Route::post('/v1/rest-login', [RestAuthApiController::class, 'login']); Route::post('/v1/rest-forgot-password', [RestAuthApiController::class, 'restForgotPassword']);