Files
cheerstothe_season_2.0/app/Http/Controllers/APIs/RestaurantApi/RestAuthApiController.php
sayaliparab 6aa37e8ba0 Changestoday
2024-05-29 14:53:06 +05:30

70 lines
2.4 KiB
PHP

<?php
namespace App\Http\Controllers\APIs\RestaurantApi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\APIs\RestaurantService\RestAuthApiService;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
class RestAuthApiController extends Controller
{
protected $RestAuthApiService;
public function __construct(RestAuthApiService $RestAuthApiService)
{
$this->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);
}
}
}