From 16216442435b3297a28c4790350a21cbc13bb5bd Mon Sep 17 00:00:00 2001 From: Priceless-P Date: Thu, 17 Nov 2022 11:12:33 +0100 Subject: [PATCH 1/3] feat: add get user by Id in issue #18' --- .../Http/Controllers/User/UserController.php | 28 +++++++++++++++++-- backend/routes/api.php | 5 ++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/backend/app/Http/Controllers/User/UserController.php b/backend/app/Http/Controllers/User/UserController.php index eee9c603..3700abcb 100644 --- a/backend/app/Http/Controllers/User/UserController.php +++ b/backend/app/Http/Controllers/User/UserController.php @@ -2,12 +2,36 @@ namespace App\Http\Controllers\User; -use App\Http\Controllers\Controller; use App\Models\User; +use function response; use App\Services\UserService; +use Illuminate\Http\JsonResponse; +use App\Http\Controllers\Controller; + class UserController extends Controller { + public function getUserById($user_id): JsonResponse + { + if (User::where('id', $user_id)->exists()) + { + $user = User::find($user_id); + return response()->json([ + 'error' => false, + 'message' => "User Found", + 'data' => $user + ]); + } + else + { + return response()->json([ + 'error' => false, + 'message' => "User does not exist", + 'data' => null + ], 404); + } + } + public function getVerifiedUserById($userId) { $verified_user = UserService::getVerifiedUser($userId); @@ -24,4 +48,4 @@ public function getVerifiedUserById($userId) 'user' => $verified_user ], 200); } -} \ No newline at end of file +} diff --git a/backend/routes/api.php b/backend/routes/api.php index 2458ce0a..bad954c0 100644 --- a/backend/routes/api.php +++ b/backend/routes/api.php @@ -25,9 +25,10 @@ // other route functions here Route::get("/test", function(){ // execute the function - return sendResponse(false, 200, "Test case pass", null); + return sendResponse(false, 200, "Test case pass", null); }); Route::prefix("users")->group(function(){ + Route::get('{id}', [UserController::class, 'getUserById']); Route::get('verified/{userId}', [UserController::class, 'getVerifiedUserById']); -}); \ No newline at end of file +}); From f1b927575f8661d845d2fe0f0239b53307a258e3 Mon Sep 17 00:00:00 2001 From: Priceless-P Date: Thu, 17 Nov 2022 11:14:07 +0100 Subject: [PATCH 2/3] fix:change user path --- backend/routes/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/routes/api.php b/backend/routes/api.php index bad954c0..a45038d3 100644 --- a/backend/routes/api.php +++ b/backend/routes/api.php @@ -2,7 +2,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; -use App\Http\Controllers\User\UserController; +use App\Http\Controllers\UserController; // util functions require_once "../util/sendResponse.php"; From 0e807d8e7d65cd6cedcc48b020cc863b6c5ceae7 Mon Sep 17 00:00:00 2001 From: Priceless-P Date: Thu, 17 Nov 2022 11:19:15 +0100 Subject: [PATCH 3/3] fix:chage UserController path --- .idea/workspace.xml | 33 +++++++++++++++++++++++++++++++++ backend/routes/api.php | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..d61616da --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/backend/routes/api.php b/backend/routes/api.php index a45038d3..bad954c0 100644 --- a/backend/routes/api.php +++ b/backend/routes/api.php @@ -2,7 +2,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; -use App\Http\Controllers\UserController; +use App\Http\Controllers\User\UserController; // util functions require_once "../util/sendResponse.php";