From 2f1df6c117d3a08c457a1ecf14f7a3c58179e9cf Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 23 May 2024 19:28:29 +0200 Subject: [PATCH] Can toggle accommodations module --- geneit_app/src/api/FamilyApi.ts | 4 ++++ .../src/routes/family/FamilySettingsRoute.tsx | 17 ++++++++++++++--- .../down.sql | 3 +++ .../up.sql | 7 +++++++ .../src/controllers/families_controller.rs | 7 +++++++ geneit_backend/src/main.rs | 11 +++++++++++ geneit_backend/src/models.rs | 1 + geneit_backend/src/schema.rs | 1 + geneit_backend/src/services/families_service.rs | 1 + 9 files changed, 49 insertions(+), 3 deletions(-) diff --git a/geneit_app/src/api/FamilyApi.ts b/geneit_app/src/api/FamilyApi.ts index 31d97b6..590fdd1 100644 --- a/geneit_app/src/api/FamilyApi.ts +++ b/geneit_app/src/api/FamilyApi.ts @@ -88,10 +88,12 @@ export class Family implements FamilyAPI { export class ExtendedFamilyInfo extends Family { public disable_couple_photos: boolean; public enable_genealogy: boolean; + public enable_accommodations: boolean; constructor(p: any) { super(p); this.disable_couple_photos = p.disable_couple_photos; this.enable_genealogy = p.enable_genealogy; + this.enable_accommodations = p.enable_accommodations; } } @@ -235,6 +237,7 @@ export class FamilyApi { id: number; name?: string; enable_genealogy?: boolean; + enable_accommodations?: boolean; disable_couple_photos?: boolean; }): Promise { await APIClient.exec({ @@ -243,6 +246,7 @@ export class FamilyApi { jsonData: { name: settings.name, enable_genealogy: settings.enable_genealogy, + enable_accommodations: settings.enable_accommodations, disable_couple_photos: settings.disable_couple_photos, }, }); diff --git a/geneit_app/src/routes/family/FamilySettingsRoute.tsx b/geneit_app/src/routes/family/FamilySettingsRoute.tsx index 7c0d720..c14ddf1 100644 --- a/geneit_app/src/routes/family/FamilySettingsRoute.tsx +++ b/geneit_app/src/routes/family/FamilySettingsRoute.tsx @@ -71,6 +71,9 @@ function FamilySettingsCard(): React.ReactElement { const [enableGenealogy, setEnableGenealogy] = React.useState( family.family.enable_genealogy ); + const [enableAccommodations, setEnableAccommodations] = React.useState( + family.family.enable_accommodations + ); const canEdit = family.family.is_admin; @@ -86,6 +89,7 @@ function FamilySettingsCard(): React.ReactElement { id: family.family.family_id, name: newName, enable_genealogy: enableGenealogy, + enable_accommodations: enableAccommodations, }); family.reloadFamilyInfo(); @@ -118,14 +122,12 @@ function FamilySettingsCard(): React.ReactElement { label="Identifiant" value={family.family.family_id} /> - - - + setEnableAccommodations(c)} + /> + } + label="Activer le module de réservation de logements" + /> diff --git a/geneit_backend/migrations/2024-05-23-163128_accommodation_module/down.sql b/geneit_backend/migrations/2024-05-23-163128_accommodation_module/down.sql index d6be2c6..ab5440a 100644 --- a/geneit_backend/migrations/2024-05-23-163128_accommodation_module/down.sql +++ b/geneit_backend/migrations/2024-05-23-163128_accommodation_module/down.sql @@ -1,2 +1,5 @@ +ALTER TABLE public.families + DROP COLUMN enable_accommodations; + DROP TABLE IF EXISTS accomodations_reservations; DROP TABLE IF EXISTS accomodations_list; \ No newline at end of file diff --git a/geneit_backend/migrations/2024-05-23-163128_accommodation_module/up.sql b/geneit_backend/migrations/2024-05-23-163128_accommodation_module/up.sql index e1456f7..0262ead 100644 --- a/geneit_backend/migrations/2024-05-23-163128_accommodation_module/up.sql +++ b/geneit_backend/migrations/2024-05-23-163128_accommodation_module/up.sql @@ -1,3 +1,10 @@ +-- Add column to toggle accommodations module +ALTER TABLE public.families + ADD enable_accommodations boolean NOT NULL DEFAULT false; +COMMENT + ON COLUMN public.families.enable_accommodations IS 'Specify whether accommodations feature is enabled for the family'; + + -- Create tables CREATE TABLE IF NOT EXISTS accommodations_list ( diff --git a/geneit_backend/src/controllers/families_controller.rs b/geneit_backend/src/controllers/families_controller.rs index b5b4c3e..8183db1 100644 --- a/geneit_backend/src/controllers/families_controller.rs +++ b/geneit_backend/src/controllers/families_controller.rs @@ -80,6 +80,7 @@ struct RichFamilyInfo { #[serde(flatten)] membership: FamilyMembership, enable_genealogy: bool, + enable_accommodations: bool, disable_couple_photos: bool, } @@ -90,6 +91,7 @@ pub async fn single_info(f: FamilyInPath) -> HttpResult { Ok(HttpResponse::Ok().json(RichFamilyInfo { membership, enable_genealogy: family.enable_genealogy, + enable_accommodations: family.enable_accommodations, disable_couple_photos: family.disable_couple_photos, })) } @@ -105,6 +107,7 @@ pub async fn leave(f: FamilyInPath) -> HttpResult { pub struct UpdateFamilyBody { name: Option, enable_genealogy: Option, + enable_accommodations: Option, disable_couple_photos: Option, } @@ -127,6 +130,10 @@ pub async fn update( family.enable_genealogy = enable_genealogy; } + if let Some(enable_accommodations) = req.enable_accommodations { + family.enable_accommodations = enable_accommodations; + } + if let Some(disable_couple_photos) = req.disable_couple_photos { family.disable_couple_photos = disable_couple_photos; } diff --git a/geneit_backend/src/main.rs b/geneit_backend/src/main.rs index 683dfcb..9fa9c26 100644 --- a/geneit_backend/src/main.rs +++ b/geneit_backend/src/main.rs @@ -204,6 +204,17 @@ async fn main() -> std::io::Result<()> { "/family/{id}/genealogy/data/import", web::put().to(data_controller::import_family), ) + // [ACCOMODATIONS] List controller + // TODO : create + // TODO : update + // TODO : delete + // TODO : list + // [ACCOMODATIONS] Reservations controller + // TODO : create + // TODO : update + // TODO : delete + // TODO : list + // TODO : validate or reject // Photos controller .route( "/photo/{id}", diff --git a/geneit_backend/src/models.rs b/geneit_backend/src/models.rs index 596d092..d1dd017 100644 --- a/geneit_backend/src/models.rs +++ b/geneit_backend/src/models.rs @@ -66,6 +66,7 @@ pub struct Family { pub invitation_code: String, pub disable_couple_photos: bool, pub enable_genealogy: bool, + pub enable_accommodations: bool, } impl Family { diff --git a/geneit_backend/src/schema.rs b/geneit_backend/src/schema.rs index 4ab6a0f..7c4d774 100644 --- a/geneit_backend/src/schema.rs +++ b/geneit_backend/src/schema.rs @@ -56,6 +56,7 @@ diesel::table! { invitation_code -> Varchar, disable_couple_photos -> Bool, enable_genealogy -> Bool, + enable_accommodations -> Bool, } } diff --git a/geneit_backend/src/services/families_service.rs b/geneit_backend/src/services/families_service.rs index af6dd93..a1fc6e7 100644 --- a/geneit_backend/src/services/families_service.rs +++ b/geneit_backend/src/services/families_service.rs @@ -175,6 +175,7 @@ pub async fn update_family(family: &Family) -> anyhow::Result<()> { families::dsl::name.eq(family.name.clone()), families::dsl::invitation_code.eq(family.invitation_code.clone()), families::dsl::enable_genealogy.eq(family.enable_genealogy), + families::dsl::enable_accommodations.eq(family.enable_accommodations), families::dsl::disable_couple_photos.eq(family.disable_couple_photos), )) .execute(conn)