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))
|
||||
}
|
@ -5,8 +5,9 @@ use actix_web::HttpResponse;
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
|
||||
pub mod auth_controller;
|
||||
pub mod families_controller;
|
||||
pub mod server_controller;
|
||||
pub mod user_controller;
|
||||
pub mod users_controller;
|
||||
|
||||
/// Custom error to ease controller writing
|
||||
#[derive(Debug)]
|
||||
|
Reference in New Issue
Block a user