Can create a family
This commit is contained in:
24
geneit_backend/src/controllers/families_controller.rs
Normal file
24
geneit_backend/src/controllers/families_controller.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use crate::constants::StaticConstraints;
|
||||
use crate::controllers::HttpResult;
|
||||
use crate::services::families_service;
|
||||
use crate::services::login_token_service::LoginToken;
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct CreateFamilyReq {
|
||||
name: String,
|
||||
}
|
||||
|
||||
/// Create a new family
|
||||
pub async fn create(req: web::Json<CreateFamilyReq>, token: LoginToken) -> HttpResult {
|
||||
if !StaticConstraints::default()
|
||||
.family_name_len
|
||||
.validate(&req.name)
|
||||
{
|
||||
return Ok(HttpResponse::BadRequest().body("Invalid family name!"));
|
||||
}
|
||||
|
||||
let family = families_service::create(&req.name, token.user_id).await?;
|
||||
|
||||
Ok(HttpResponse::Created().json(family))
|
||||
}
|
Reference in New Issue
Block a user