summaryrefslogtreecommitdiff
path: root/server/src/routes
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-12-01 10:39:18 +0100
committerSanto Cariotti <santo@dcariotti.me>2022-12-01 10:39:18 +0100
commit2541e3cd60acad79117c5f6d10fbdf86f3f8c7f6 (patch)
tree65262feaf9b05a45ae1fda73143a0c2c750c0692 /server/src/routes
parent4371ba5f0916147e8d60237d1e2fbb6a1fdf834a (diff)
Use /me instead of all users
Diffstat (limited to 'server/src/routes')
-rw-r--r--server/src/routes/user.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/server/src/routes/user.rs b/server/src/routes/user.rs
index d5a09e2..1bb56b9 100644
--- a/server/src/routes/user.rs
+++ b/server/src/routes/user.rs
@@ -8,15 +8,16 @@ use axum::{extract::Path, routing::get, Json, Router};
/// Create routes for `/v1/users/` namespace
pub fn create_route() -> Router {
Router::new()
- .route("/", get(list_users))
+ .route("/", get(get_me))
.route("/:id", get(get_user))
}
-/// List users. Checks Authorization token
-async fn list_users(_: Claims) -> Result<Json<Vec<UserList>>, AppError> {
- let users = User::list().await?;
-
- Ok(Json(users))
+/// 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())),
+ }
}
/// Search an user by `user_id`. It works only if the user passed by `Authorization` token is the