summaryrefslogtreecommitdiff
path: root/server/src/routes
diff options
context:
space:
mode:
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)),