summaryrefslogtreecommitdiff
path: root/server/src/routes
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/routes')
-rw-r--r--server/src/routes/user.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/server/src/routes/user.rs b/server/src/routes/user.rs
index 1b43e01..7aecccb 100644
--- a/server/src/routes/user.rs
+++ b/server/src/routes/user.rs
@@ -1,9 +1,12 @@
use crate::errors::AppError;
-use crate::models::user::{User, UserList};
-use axum::{routing::get, Json, Router};
+use crate::models::user::{User, UserCreate, UserList};
+use axum::{
+ routing::{get},
+ Json, Router,
+};
pub fn create_route() -> Router {
- Router::new().route("/", get(list_users))
+ Router::new().route("/", get(list_users).post(create_user))
}
async fn list_users() -> Result<Json<Vec<UserList>>, AppError> {
@@ -11,3 +14,10 @@ async fn list_users() -> Result<Json<Vec<UserList>>, AppError> {
Ok(Json(users))
}
+
+async fn create_user(Json(payload): Json<UserCreate>) -> Result<Json<UserList>, AppError> {
+ let user = User::new(payload.email, payload.password);
+ let user_new = User::create(user).await?;
+
+ Ok(Json(user_new))
+}