summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-08-22 17:30:28 +0200
committerSanto Cariotti <santo@dcariotti.me>2022-08-22 17:30:28 +0200
commitd346c13beb54baa334326d80bb4ba2e48653ce06 (patch)
tree22ddb47fc2dd57647fd8ee339c6b6be4f8494889 /server
parent5b32f1eb39f14457a11701095218524fc50f5a73 (diff)
Routes for users
Diffstat (limited to 'server')
-rw-r--r--server/src/main.rs4
-rw-r--r--server/src/routes/mod.rs1
-rw-r--r--server/src/routes/user.rs13
3 files changed, 18 insertions, 0 deletions
diff --git a/server/src/main.rs b/server/src/main.rs
index a61e44b..e2536ca 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -2,6 +2,7 @@ mod db;
mod errors;
mod logger;
mod models;
+mod routes;
use axum::{
http::{header, Request},
@@ -30,7 +31,10 @@ async fn create_app() -> Router {
logger::setup();
let _ = db::setup().await;
+ let api_routes = Router::new().nest("/users", routes::user::create_route());
+
Router::new()
+ .nest("/v1", api_routes)
// Mark the `Authorization` request header as sensitive so it doesn't
// show in logs.
.layer(SetSensitiveHeadersLayer::new(std::iter::once(
diff --git a/server/src/routes/mod.rs b/server/src/routes/mod.rs
new file mode 100644
index 0000000..22d12a3
--- /dev/null
+++ b/server/src/routes/mod.rs
@@ -0,0 +1 @@
+pub mod user;
diff --git a/server/src/routes/user.rs b/server/src/routes/user.rs
new file mode 100644
index 0000000..f155f27
--- /dev/null
+++ b/server/src/routes/user.rs
@@ -0,0 +1,13 @@
+use crate::errors::AppError;
+use crate::models::user::User;
+use axum::{routing::get, Json, Router};
+
+pub fn create_route() -> Router {
+ Router::new().route("/", get(list_users))
+}
+
+async fn list_users() -> Result<Json<Vec<User>>, AppError> {
+ let users = User::list().await?;
+
+ Ok(Json(users))
+}