diff options
-rw-r--r-- | server/src/main.rs | 4 | ||||
-rw-r--r-- | server/src/routes/mod.rs | 1 | ||||
-rw-r--r-- | server/src/routes/user.rs | 13 |
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)) +} |