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, 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)) }