From 2231ab6730552d3b58b00ae42d490743a29d7c8b Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 23 Aug 2022 18:57:16 +0200 Subject: Add docs --- server/src/routes/auth.rs | 3 +++ server/src/routes/user.rs | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'server/src/routes') diff --git a/server/src/routes/auth.rs b/server/src/routes/auth.rs index 629ed33..37c41b2 100644 --- a/server/src/routes/auth.rs +++ b/server/src/routes/auth.rs @@ -5,10 +5,13 @@ use crate::models::{ }; use axum::{routing::post, Json, Router}; +/// Create routes for `/v1/auth/` namespace pub fn create_route() -> Router { Router::new().route("/login", post(make_login)) } +/// Make login. Check if a user with the email and password passed in request body exists into the +/// database async fn make_login(Json(payload): Json) -> Result, AppError> { let user = User::new(payload.email, payload.password); match User::find(user).await { diff --git a/server/src/routes/user.rs b/server/src/routes/user.rs index 3ca0e7b..d44df66 100644 --- a/server/src/routes/user.rs +++ b/server/src/routes/user.rs @@ -5,18 +5,21 @@ use crate::models::{ }; 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).post(create_user)) .route("/:id", get(get_user)) } +/// List users. Checks Authorization token async fn list_users(_: Claims) -> Result>, AppError> { let users = User::list().await?; Ok(Json(users)) } +/// Create an user. Checks Authorization token async fn create_user( Json(payload): Json, _: Claims, @@ -27,6 +30,7 @@ async fn create_user( Ok(Json(user_new)) } +/// Get an user with id = `user_id`. Checks Authorization token async fn get_user(Path(user_id): Path, _: Claims) -> Result, AppError> { match User::find_by_id(user_id).await { Ok(user) => Ok(Json(user)), -- cgit v1.2.3-18-g5258