2024-05-29 17:13:40 +05:30
|
|
|
<?php
|
|
|
|
|
|
2024-06-30 21:11:10 +05:30
|
|
|
namespace App\Http\Controllers\APIs\RestaurantApi;
|
2024-06-12 13:56:42 +05:30
|
|
|
|
2024-05-29 17:13:40 +05:30
|
|
|
use App\Services\APIs\RestaurantService\RestAuthApiService;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
use Illuminate\Validation\Rule;
|
2024-06-03 11:41:00 +05:30
|
|
|
use App\Models\IamPrincipal;
|
2024-05-29 17:13:40 +05:30
|
|
|
|
|
|
|
|
|
2024-05-30 19:41:43 +05:30
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use Illuminate\Http\Request;
|
2024-05-29 17:13:40 +05:30
|
|
|
|
|
|
|
|
class RestAuthApiController extends Controller
|
|
|
|
|
{
|
|
|
|
|
protected $RestAuthApiService;
|
|
|
|
|
|
|
|
|
|
public function __construct(RestAuthApiService $RestAuthApiService)
|
|
|
|
|
{
|
|
|
|
|
$this->RestAuthApiService = $RestAuthApiService;
|
2024-06-11 17:57:57 +05:30
|
|
|
}
|
2024-05-29 17:13:40 +05:30
|
|
|
|
2024-06-03 11:41:00 +05:30
|
|
|
/**
|
|
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 30 May 2024
|
|
|
|
|
* Use : Restaurant Details.
|
|
|
|
|
*/
|
2024-05-29 17:13:40 +05:30
|
|
|
public function viewresyaurant()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$response = $this->RestAuthApiService->viewresyaurant();
|
2024-05-30 19:41:43 +05:30
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-12 13:56:42 +05:30
|
|
|
/**
|
2024-06-03 11:41:00 +05:30
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 30 May 2024
|
|
|
|
|
* Use : Restaurant State.
|
|
|
|
|
*/
|
2024-05-30 19:41:43 +05:30
|
|
|
public function viewstates()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$response = $this->RestAuthApiService->viewstates();
|
2024-05-29 17:13:40 +05:30
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-12 13:56:42 +05:30
|
|
|
/**
|
2024-06-03 11:41:00 +05:30
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 30 May 2024
|
|
|
|
|
* Use : Restaurant Registration.
|
|
|
|
|
*/
|
2024-05-29 17:13:40 +05:30
|
|
|
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',
|
2024-06-11 17:57:57 +05:30
|
|
|
// 'state_xid'=>'required',
|
2024-05-29 17:13:40 +05:30
|
|
|
'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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-12 13:56:42 +05:30
|
|
|
/**
|
|
|
|
|
* Created By : sayali parab
|
2024-06-03 11:41:00 +05:30
|
|
|
* Created at : 31 May 2024
|
|
|
|
|
* Use : Restaurant login.
|
|
|
|
|
*/
|
2024-05-29 17:13:40 +05:30
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-12 13:56:42 +05:30
|
|
|
/**
|
2024-06-03 11:41:00 +05:30
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 31 May 2024
|
|
|
|
|
* Use : Forgot password for restaurant.
|
|
|
|
|
*/
|
|
|
|
|
public function restForgotPassword(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
|
|
|
'email_address' => [
|
|
|
|
|
'required',
|
|
|
|
|
'string',
|
|
|
|
|
'email',
|
2024-08-06 17:15:55 +05:30
|
|
|
function ($attribute, $value, $fail) {
|
2024-08-06 17:20:13 +05:30
|
|
|
$existingUser = IamPrincipal::where('email_address', $value)->where('principal_type_xid', 4)->where('is_active', 1)->whereNull('deleted_at')->exists();
|
2024-08-06 17:15:55 +05:30
|
|
|
if (!$existingUser) {
|
2024-08-06 19:36:55 +05:30
|
|
|
$fail('Entered e-mail address is not in our system..');
|
2024-08-06 17:15:55 +05:30
|
|
|
}
|
|
|
|
|
},
|
2024-06-03 11:41:00 +05:30
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-12 13:56:42 +05:30
|
|
|
/**
|
2024-06-03 11:41:00 +05:30
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 31 May 2024
|
|
|
|
|
* Use : verify otp for restaurant.
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 31 May 2024
|
|
|
|
|
* Use : Change password for restaurant.
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 31 May 2024
|
|
|
|
|
* Use : Resend otp for restaurant.
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-12 13:56:42 +05:30
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created By : Sayli Raut
|
|
|
|
|
* Created at : 12 June 2024
|
|
|
|
|
* Use : Search Restaurant .
|
|
|
|
|
*/
|
|
|
|
|
public function searchRest(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->RestAuthApiService->searchRest($request);
|
|
|
|
|
} catch (\Exception $ex) {
|
|
|
|
|
Log::error("Login API Failed: " . $ex->getMessage());
|
|
|
|
|
return jsonResponseWithErrorMessage(__('error_message.something_went_wrong'), 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-06 17:15:55 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-05-29 17:13:40 +05:30
|
|
|
}
|