Skip to content

Commit

Permalink
feat: add get user by Id in issue #18'
Browse files Browse the repository at this point in the history
  • Loading branch information
Priceless-P committed Nov 17, 2022
1 parent bec8936 commit 1621644
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
28 changes: 26 additions & 2 deletions backend/app/Http/Controllers/User/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -24,4 +48,4 @@ public function getVerifiedUserById($userId)
'user' => $verified_user
], 200);
}
}
}
5 changes: 3 additions & 2 deletions backend/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
});

0 comments on commit 1621644

Please sign in to comment.