Separate genealogy settings from family settings
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
2024-05-16 20:39:37 +02:00
parent 28b29d6cd6
commit 9c8b424759
6 changed files with 257 additions and 153 deletions

View File

@ -103,9 +103,9 @@ pub async fn leave(f: FamilyInPath) -> HttpResult {
#[derive(serde::Deserialize)]
pub struct UpdateFamilyBody {
name: String,
enable_genealogy: bool,
disable_couple_photos: bool,
name: Option<String>,
enable_genealogy: Option<bool>,
disable_couple_photos: Option<bool>,
}
/// Update a family
@ -113,17 +113,24 @@ pub async fn update(
f: FamilyInPathWithAdminMembership,
req: web::Json<UpdateFamilyBody>,
) -> HttpResult {
if !StaticConstraints::default()
.family_name_len
.validate(&req.name)
{
return Ok(HttpResponse::BadRequest().body("Invalid family name!"));
let mut family = families_service::get_by_id(f.family_id()).await?;
if let Some(name) = &req.name {
if !StaticConstraints::default().family_name_len.validate(name) {
return Ok(HttpResponse::BadRequest().body("Invalid family name!"));
}
family.name = name.to_string();
}
if let Some(enable_genealogy) = req.enable_genealogy {
family.enable_genealogy = enable_genealogy;
}
if let Some(disable_couple_photos) = req.disable_couple_photos {
family.disable_couple_photos = disable_couple_photos;
}
let mut family = families_service::get_by_id(f.family_id()).await?;
family.name = req.0.name;
family.enable_genealogy = req.0.enable_genealogy;
family.disable_couple_photos = req.0.disable_couple_photos;
families_service::update_family(&family).await?;
log::info!("User {:?} updated family {:?}", f.user_id(), f.family_id());