diff options
Diffstat (limited to 'server/src/routes')
-rw-r--r-- | server/src/routes/user.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/server/src/routes/user.rs b/server/src/routes/user.rs index 7aecccb..c15b5aa 100644 --- a/server/src/routes/user.rs +++ b/server/src/routes/user.rs @@ -1,9 +1,7 @@ use crate::errors::AppError; use crate::models::user::{User, UserCreate, UserList}; -use axum::{ - routing::{get}, - Json, Router, -}; +use axum::{routing::get, Json, Router}; +use validator::Validate; pub fn create_route() -> Router { Router::new().route("/", get(list_users).post(create_user)) @@ -17,6 +15,8 @@ async fn list_users() -> Result<Json<Vec<UserList>>, AppError> { async fn create_user(Json(payload): Json<UserCreate>) -> Result<Json<UserList>, AppError> { let user = User::new(payload.email, payload.password); + user.validate() + .map_err(|error| AppError::BadRequest(error.to_string()))?; let user_new = User::create(user).await?; Ok(Json(user_new)) |