diff --git a/backend/app/Http/Controllers/Controller.php b/backend/app/Http/Controllers/Controller.php index a0a2a8a3..48425237 100644 --- a/backend/app/Http/Controllers/Controller.php +++ b/backend/app/Http/Controllers/Controller.php @@ -10,4 +10,58 @@ class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests; + + /** + * @param $message + * @return Response + */ + protected function respondWithMissingField($message) + { + return response()->json([ + 'status' => 400, + 'message' => $message, + ], 400); + } + + /** + * @param $message + * @return Response + */ + private function respondWithValidationError($message) + { + return response()->json([ + 'status' => false, + 'message' => $message, + ], 400); + } + + /** + * @param $validator + * @return Response + */ + protected function respondWithErrorMessage($validator) + { + $required = $messages = []; + $validatorMessages = $validator->errors()->toArray(); + foreach($validatorMessages as $field => $message) { + if (strpos($message[0], 'required')) { + $required[] = $field; + } + + foreach ($message as $error) { + $messages[] = $error; + } + } + + if (count($required) > 0) { + $fields = implode(', ', $required); + $message = "Missing required fields $fields"; + + return $this->respondWithMissingField($message); + } + + + return $this->respondWithValidationError(implode(', ', $messages)); + } + } diff --git a/backend/app/Http/Controllers/User/UserController.php b/backend/app/Http/Controllers/User/UserController.php new file mode 100644 index 00000000..eee9c603 --- /dev/null +++ b/backend/app/Http/Controllers/User/UserController.php @@ -0,0 +1,27 @@ +json([ + 'status' => false, + 'message' => 'User does not exist or is not a verified user' + ], 404); + } + + return response()->json([ + 'status' => true, + 'user' => $verified_user + ], 200); + } +} \ No newline at end of file diff --git a/backend/app/Services/UserService.php b/backend/app/Services/UserService.php new file mode 100644 index 00000000..2943f60c --- /dev/null +++ b/backend/app/Services/UserService.php @@ -0,0 +1,19 @@ +where('isVerified', true)->first(); + + return $user; + } +} \ No newline at end of file diff --git a/backend/routes/api.php b/backend/routes/api.php index eb6fa48c..acf3f9b6 100644 --- a/backend/routes/api.php +++ b/backend/routes/api.php @@ -2,6 +2,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; +use App\Http\Controllers\User\UserController; /* |-------------------------------------------------------------------------- @@ -17,3 +18,7 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) { return $request->user(); }); + +Route::group(['prefix' => 'users'], function() { + Route::get('verified/{userId}', [UserController::class, 'getVerifiedUserById']); +}); \ No newline at end of file