diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2022-09-13 13:24:03 +0000 |
|---|---|---|
| committer | Santo Cariotti <santo@dcariotti.me> | 2022-09-13 13:24:03 +0000 |
| commit | ef0b36620e43f8cee6d1857de340f975cec25685 (patch) | |
| tree | e31742673c5ad791faed5601277d2894440c420f | |
| parent | bcff6540a98056c4b1f90e0efd784eb2b41f347f (diff) | |
Add `/me` endpoint
| -rw-r--r-- | src/routes/user.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/routes/user.rs b/src/routes/user.rs index 8c2ec0e..00e2980 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -15,6 +15,7 @@ use serde::Serialize; pub fn create_route() -> Router { Router::new() .route("/", get(list_users)) + .route("/me", get(get_me)) .route("/:id", get(get_user)) } @@ -36,6 +37,14 @@ async fn list_users( Ok(Json(UserPagination { count, results })) } +/// Get info about me +async fn get_me(claims: Claims) -> Result<Json<UserList>, AppError> { + match User::find_by_id(claims.user_id).await { + Ok(user) => Ok(Json(user)), + Err(_) => Err(AppError::NotFound("User not found".to_string())), + } +} + /// Get an user with id = `user_id`. Checks Authorization token async fn get_user(Path(user_id): Path<i32>, _: Claims) -> Result<Json<UserList>, AppError> { match User::find_by_id(user_id).await { |
