Can disable couple photos #5

Merged
pierre merged 7 commits from disable_couple_photos into master 2023-08-26 14:55:24 +00:00
3 changed files with 18 additions and 3 deletions
Showing only changes of commit dd8ba0a84f - Show all commits

View File

@ -1,7 +1,7 @@
use crate::constants::{StaticConstraints, FAMILY_INVITATION_CODE_LEN}; use crate::constants::{StaticConstraints, FAMILY_INVITATION_CODE_LEN};
use crate::controllers::HttpResult; use crate::controllers::HttpResult;
use crate::extractors::family_extractor::{FamilyInPath, FamilyInPathWithAdminMembership}; 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::login_token_service::LoginToken;
use crate::services::rate_limiter_service::RatedAction; use crate::services::rate_limiter_service::RatedAction;
use crate::services::{families_service, rate_limiter_service}; 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 /// Get the information of a single family
pub async fn single_info(f: FamilyInPath) -> HttpResult { pub async fn single_info(f: FamilyInPath) -> HttpResult {
Ok(HttpResponse::Ok() let membership = families_service::get_family_membership(f.family_id(), f.user_id()).await?;
.json(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 /// Attempt to leave a family
@ -91,6 +102,7 @@ pub async fn leave(f: FamilyInPath) -> HttpResult {
#[derive(serde::Deserialize)] #[derive(serde::Deserialize)]
pub struct UpdateFamilyBody { pub struct UpdateFamilyBody {
name: String, name: String,
disable_couple_photos: bool,
} }
/// Update a family /// Update a family
@ -107,6 +119,7 @@ pub async fn update(
let mut family = families_service::get_by_id(f.family_id()).await?; let mut family = families_service::get_by_id(f.family_id()).await?;
family.name = req.0.name; family.name = req.0.name;
family.disable_couple_photos = req.0.disable_couple_photos;
families_service::update_family(&family).await?; families_service::update_family(&family).await?;
log::info!("User {:?} updated family {:?}", f.user_id(), f.family_id()); log::info!("User {:?} updated family {:?}", f.user_id(), f.family_id());

View File

@ -64,6 +64,7 @@ pub struct Family {
pub time_create: i64, pub time_create: i64,
pub name: String, pub name: String,
pub invitation_code: String, pub invitation_code: String,
pub disable_couple_photos: bool,
} }
impl Family { impl Family {

View File

@ -174,6 +174,7 @@ pub async fn update_family(family: &Family) -> anyhow::Result<()> {
.set(( .set((
families::dsl::name.eq(family.name.clone()), families::dsl::name.eq(family.name.clone()),
families::dsl::invitation_code.eq(family.invitation_code.clone()), families::dsl::invitation_code.eq(family.invitation_code.clone()),
families::dsl::disable_couple_photos.eq(family.disable_couple_photos),
)) ))
.execute(conn) .execute(conn)
})?; })?;