summaryrefslogtreecommitdiff
path: root/server/src/routes
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-08-23 18:57:16 +0200
committerSanto Cariotti <santo@dcariotti.me>2022-08-23 18:57:16 +0200
commit2231ab6730552d3b58b00ae42d490743a29d7c8b (patch)
tree4a9612ec08398b8abc2e4ce7c30825f7ef18659c /server/src/routes
parentbba5f252f265e6102d2f052e9ca100efe318508f (diff)
Add docs
Diffstat (limited to 'server/src/routes')
-rw-r--r--server/src/routes/auth.rs3
-rw-r--r--server/src/routes/user.rs4
2 files changed, 7 insertions, 0 deletions
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<UserCreate>) -> Result<Json<AuthBody>, 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<Json<Vec<UserList>>, AppError> {
let users = User::list().await?;
Ok(Json(users))
}
+/// Create an user. Checks Authorization token
async fn create_user(
Json(payload): Json<UserCreate>,
_: 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<i32>, _: Claims) -> Result<Json<UserList>, AppError> {
match User::find_by_id(user_id).await {
Ok(user) => Ok(Json(user)),