From dd8ba0a84f23d957c5fc34cec6cace14f7c312dc Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Sat, 26 Aug 2023 16:22:20 +0200 Subject: [PATCH] Add support for new configuration field in backend --- .../src/controllers/families_controller.rs | 19 ++++++++++++++++--- geneit_backend/src/models.rs | 1 + .../src/services/families_service.rs | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/geneit_backend/src/controllers/families_controller.rs b/geneit_backend/src/controllers/families_controller.rs index 5b5f4c0..d5c3f92 100644 --- a/geneit_backend/src/controllers/families_controller.rs +++ b/geneit_backend/src/controllers/families_controller.rs @@ -1,7 +1,7 @@ use crate::constants::{StaticConstraints, FAMILY_INVITATION_CODE_LEN}; use crate::controllers::HttpResult; use crate::extractors::family_extractor::{FamilyInPath, FamilyInPathWithAdminMembership}; -use crate::models::UserID; +use crate::models::{FamilyMembership, UserID}; use crate::services::login_token_service::LoginToken; use crate::services::rate_limiter_service::RatedAction; use crate::services::{families_service, rate_limiter_service}; @@ -75,10 +75,21 @@ pub async fn list(token: LoginToken) -> HttpResult { ) } +#[derive(serde::Serialize)] +struct RichFamilyInfo { + #[serde(flatten)] + membership: FamilyMembership, + disable_couple_photos: bool, +} + /// Get the information of a single family pub async fn single_info(f: FamilyInPath) -> HttpResult { - Ok(HttpResponse::Ok() - .json(families_service::get_family_membership(f.family_id(), f.user_id()).await?)) + let membership = families_service::get_family_membership(f.family_id(), f.user_id()).await?; + let family = families_service::get_by_id(f.family_id()).await?; + Ok(HttpResponse::Ok().json(RichFamilyInfo { + membership, + disable_couple_photos: family.disable_couple_photos, + })) } /// Attempt to leave a family @@ -91,6 +102,7 @@ pub async fn leave(f: FamilyInPath) -> HttpResult { #[derive(serde::Deserialize)] pub struct UpdateFamilyBody { name: String, + disable_couple_photos: bool, } /// Update a family @@ -107,6 +119,7 @@ pub async fn update( let mut family = families_service::get_by_id(f.family_id()).await?; family.name = req.0.name; + 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()); diff --git a/geneit_backend/src/models.rs b/geneit_backend/src/models.rs index 9b39897..e901fac 100644 --- a/geneit_backend/src/models.rs +++ b/geneit_backend/src/models.rs @@ -64,6 +64,7 @@ pub struct Family { pub time_create: i64, pub name: String, pub invitation_code: String, + pub disable_couple_photos: bool, } impl Family { diff --git a/geneit_backend/src/services/families_service.rs b/geneit_backend/src/services/families_service.rs index 475b406..77c6b0c 100644 --- a/geneit_backend/src/services/families_service.rs +++ b/geneit_backend/src/services/families_service.rs @@ -174,6 +174,7 @@ pub async fn update_family(family: &Family) -> anyhow::Result<()> { .set(( families::dsl::name.eq(family.name.clone()), families::dsl::invitation_code.eq(family.invitation_code.clone()), + families::dsl::disable_couple_photos.eq(family.disable_couple_photos), )) .execute(conn) })?;