Can create a family

This commit is contained in:
2023-06-16 17:51:51 +02:00
parent e6c896efa2
commit f54dfde7f7
10 changed files with 140 additions and 17 deletions

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

View File

@ -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)]