Can disable couple photos #5
@ -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());
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
})?;
|
||||
|
Loading…
Reference in New Issue
Block a user