summaryrefslogtreecommitdiffstats
path: root/src/routes
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/user.rs9
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 {