Skip to content

Commit

Permalink
Merge pull request #39 from workshopapps/feat-getUserById
Browse files Browse the repository at this point in the history
Feat get user by id
  • Loading branch information
Benrobo authored Nov 17, 2022
2 parents 9d1b275 + 1ac2d43 commit bc38cb0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
33 changes: 33 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions backend/app/Http/Controllers/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);
}
}
}
8 changes: 7 additions & 1 deletion backend/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
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']);
});

Route::prefix("users")->group(function () {
Route::get('verified/{userId}', [UserController::class, 'getVerifiedUserById']);
});
Expand All @@ -39,4 +44,5 @@
Route::get('permissions', 'index');
Route::post('new_permission', 'store');
});
});
});

0 comments on commit bc38cb0

Please sign in to comment.