Compare commits
14 Commits
renovate/s
...
5b9d82889c
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b9d82889c | |||
| 3efae7bfff | |||
| 1332b001c8 | |||
| 6e4b6a0499 | |||
| 936b095d46 | |||
| d0d1169c7d | |||
| 9a4da0462a | |||
| 49f3677081 | |||
| 16bc7eca6f | |||
| bc800e7cf6 | |||
| 18582fdff7 | |||
| c4fadce69f | |||
| 2f1df6c117 | |||
| 32d3793025 |
@@ -88,10 +88,12 @@ export class Family implements FamilyAPI {
|
|||||||
export class ExtendedFamilyInfo extends Family {
|
export class ExtendedFamilyInfo extends Family {
|
||||||
public disable_couple_photos: boolean;
|
public disable_couple_photos: boolean;
|
||||||
public enable_genealogy: boolean;
|
public enable_genealogy: boolean;
|
||||||
|
public enable_accommodations: boolean;
|
||||||
constructor(p: any) {
|
constructor(p: any) {
|
||||||
super(p);
|
super(p);
|
||||||
this.disable_couple_photos = p.disable_couple_photos;
|
this.disable_couple_photos = p.disable_couple_photos;
|
||||||
this.enable_genealogy = p.enable_genealogy;
|
this.enable_genealogy = p.enable_genealogy;
|
||||||
|
this.enable_accommodations = p.enable_accommodations;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,6 +237,7 @@ export class FamilyApi {
|
|||||||
id: number;
|
id: number;
|
||||||
name?: string;
|
name?: string;
|
||||||
enable_genealogy?: boolean;
|
enable_genealogy?: boolean;
|
||||||
|
enable_accommodations?: boolean;
|
||||||
disable_couple_photos?: boolean;
|
disable_couple_photos?: boolean;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
await APIClient.exec({
|
await APIClient.exec({
|
||||||
@@ -243,6 +246,7 @@ export class FamilyApi {
|
|||||||
jsonData: {
|
jsonData: {
|
||||||
name: settings.name,
|
name: settings.name,
|
||||||
enable_genealogy: settings.enable_genealogy,
|
enable_genealogy: settings.enable_genealogy,
|
||||||
|
enable_accommodations: settings.enable_accommodations,
|
||||||
disable_couple_photos: settings.disable_couple_photos,
|
disable_couple_photos: settings.disable_couple_photos,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ interface Constraints {
|
|||||||
member_country: LenConstraint;
|
member_country: LenConstraint;
|
||||||
member_sex: LenConstraint;
|
member_sex: LenConstraint;
|
||||||
member_note: LenConstraint;
|
member_note: LenConstraint;
|
||||||
|
accomodation_name_len: LenConstraint;
|
||||||
|
accomodation_description_len: LenConstraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OIDCProvider {
|
interface OIDCProvider {
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ function FamilySettingsCard(): React.ReactElement {
|
|||||||
const [enableGenealogy, setEnableGenealogy] = React.useState(
|
const [enableGenealogy, setEnableGenealogy] = React.useState(
|
||||||
family.family.enable_genealogy
|
family.family.enable_genealogy
|
||||||
);
|
);
|
||||||
|
const [enableAccommodations, setEnableAccommodations] = React.useState(
|
||||||
|
family.family.enable_accommodations
|
||||||
|
);
|
||||||
|
|
||||||
const canEdit = family.family.is_admin;
|
const canEdit = family.family.is_admin;
|
||||||
|
|
||||||
@@ -86,6 +89,7 @@ function FamilySettingsCard(): React.ReactElement {
|
|||||||
id: family.family.family_id,
|
id: family.family.family_id,
|
||||||
name: newName,
|
name: newName,
|
||||||
enable_genealogy: enableGenealogy,
|
enable_genealogy: enableGenealogy,
|
||||||
|
enable_accommodations: enableAccommodations,
|
||||||
});
|
});
|
||||||
|
|
||||||
family.reloadFamilyInfo();
|
family.reloadFamilyInfo();
|
||||||
@@ -118,14 +122,12 @@ function FamilySettingsCard(): React.ReactElement {
|
|||||||
label="Identifiant"
|
label="Identifiant"
|
||||||
value={family.family.family_id}
|
value={family.family.family_id}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
disabled
|
disabled
|
||||||
fullWidth
|
fullWidth
|
||||||
label="Création de la famille"
|
label="Création de la famille"
|
||||||
value={formatDate(family.family.time_create)}
|
value={formatDate(family.family.time_create)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
fullWidth
|
fullWidth
|
||||||
label="Nom de la famille"
|
label="Nom de la famille"
|
||||||
@@ -136,7 +138,6 @@ function FamilySettingsCard(): React.ReactElement {
|
|||||||
maxLength: ServerApi.Config.constraints.family_name_len.max,
|
maxLength: ServerApi.Config.constraints.family_name_len.max,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
disabled={!canEdit}
|
disabled={!canEdit}
|
||||||
control={
|
control={
|
||||||
@@ -147,6 +148,16 @@ function FamilySettingsCard(): React.ReactElement {
|
|||||||
}
|
}
|
||||||
label="Activer le module de généalogie"
|
label="Activer le module de généalogie"
|
||||||
/>
|
/>
|
||||||
|
<FormControlLabel
|
||||||
|
disabled={!canEdit}
|
||||||
|
control={
|
||||||
|
<Switch
|
||||||
|
checked={enableAccommodations}
|
||||||
|
onChange={(_e, c) => setEnableAccommodations(c)}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
label="Activer le module de réservation de logements"
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
<CardActions>
|
<CardActions>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
ALTER TABLE public.families
|
||||||
|
DROP COLUMN enable_accommodations;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS accommodations_reservations;
|
||||||
|
DROP TABLE IF EXISTS accommodations_list;
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
-- 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
|
||||||
|
(
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
family_id integer NOT NULL REFERENCES families,
|
||||||
|
time_create BIGINT NOT NULL,
|
||||||
|
time_update BIGINT NOT NULL,
|
||||||
|
name VARCHAR(50) NOT NULL,
|
||||||
|
need_validation BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
description text NULL,
|
||||||
|
open_to_reservations BOOLEAN NOT NULL DEFAULT false
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS accommodations_reservations
|
||||||
|
(
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
family_id integer NOT NULL REFERENCES families ON DELETE CASCADE,
|
||||||
|
accommodation_id integer NOT NULL REFERENCES accommodations_list ON DELETE CASCADE,
|
||||||
|
user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||||
|
time_create BIGINT NOT NULL,
|
||||||
|
time_update BIGINT NOT NULL,
|
||||||
|
reservation_start BIGINT NOT NULL,
|
||||||
|
reservation_end BIGINT NOT NULL,
|
||||||
|
validated BOOLEAN NULL
|
||||||
|
);
|
||||||
@@ -60,6 +60,9 @@ pub struct StaticConstraints {
|
|||||||
pub member_country: SizeConstraint,
|
pub member_country: SizeConstraint,
|
||||||
pub member_sex: SizeConstraint,
|
pub member_sex: SizeConstraint,
|
||||||
pub member_note: SizeConstraint,
|
pub member_note: SizeConstraint,
|
||||||
|
|
||||||
|
pub accomodation_name_len: SizeConstraint,
|
||||||
|
pub accomodation_description_len: SizeConstraint,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for StaticConstraints {
|
impl Default for StaticConstraints {
|
||||||
@@ -91,6 +94,9 @@ impl Default for StaticConstraints {
|
|||||||
member_country: SizeConstraint::new(0, 2),
|
member_country: SizeConstraint::new(0, 2),
|
||||||
member_sex: SizeConstraint::new(0, 1),
|
member_sex: SizeConstraint::new(0, 1),
|
||||||
member_note: SizeConstraint::new(0, 35000),
|
member_note: SizeConstraint::new(0, 35000),
|
||||||
|
|
||||||
|
accomodation_name_len: SizeConstraint::new(1, 50),
|
||||||
|
accomodation_description_len: SizeConstraint::new(0, 500),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
105
geneit_backend/src/controllers/accommodations_list_controller.rs
Normal file
105
geneit_backend/src/controllers/accommodations_list_controller.rs
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
use crate::constants::StaticConstraints;
|
||||||
|
use crate::controllers::HttpResult;
|
||||||
|
use crate::extractors::accommodation_extractor::FamilyAndAccommodationInPath;
|
||||||
|
use crate::extractors::family_extractor::{FamilyInPath, FamilyInPathWithAdminMembership};
|
||||||
|
use crate::models::Accommodation;
|
||||||
|
use crate::services::accommodations_list_service;
|
||||||
|
use actix_web::{web, HttpResponse};
|
||||||
|
|
||||||
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
enum AccommodationListControllerErr {
|
||||||
|
#[error("Malformed name!")]
|
||||||
|
MalformedName,
|
||||||
|
#[error("Malformed description!")]
|
||||||
|
MalformedDescription,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, Clone)]
|
||||||
|
pub struct AccommodationRequest {
|
||||||
|
pub name: String,
|
||||||
|
pub need_validation: bool,
|
||||||
|
pub description: Option<String>,
|
||||||
|
pub open_to_reservations: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AccommodationRequest {
|
||||||
|
pub async fn to_accommodation(self, accommodation: &mut Accommodation) -> anyhow::Result<()> {
|
||||||
|
let c = StaticConstraints::default();
|
||||||
|
|
||||||
|
if !c.accomodation_name_len.validate(&self.name) {
|
||||||
|
return Err(AccommodationListControllerErr::MalformedName.into());
|
||||||
|
}
|
||||||
|
accommodation.name = self.name;
|
||||||
|
|
||||||
|
if let Some(d) = &self.description {
|
||||||
|
if !c.accomodation_description_len.validate(d) {
|
||||||
|
return Err(AccommodationListControllerErr::MalformedDescription.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
accommodation.description.clone_from(&self.description);
|
||||||
|
|
||||||
|
accommodation.need_validation = self.need_validation;
|
||||||
|
accommodation.open_to_reservations = self.open_to_reservations;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new accommodation
|
||||||
|
pub async fn create(
|
||||||
|
m: FamilyInPathWithAdminMembership,
|
||||||
|
req: web::Json<AccommodationRequest>,
|
||||||
|
) -> HttpResult {
|
||||||
|
let mut accommodation = accommodations_list_service::create(m.family_id()).await?;
|
||||||
|
|
||||||
|
if let Err(e) = req.0.to_accommodation(&mut accommodation).await {
|
||||||
|
log::error!("Failed to apply accommodation information! {e}");
|
||||||
|
accommodations_list_service::delete(&mut accommodation).await?;
|
||||||
|
return Ok(HttpResponse::BadRequest().body(e.to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(e) = accommodations_list_service::update(&mut accommodation).await {
|
||||||
|
log::error!("Failed to update accommodation information! {e}");
|
||||||
|
accommodations_list_service::delete(&mut accommodation).await?;
|
||||||
|
return Ok(HttpResponse::InternalServerError().finish());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(HttpResponse::Ok().json(accommodation))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the full list of accommodations
|
||||||
|
pub async fn get_full_list(m: FamilyInPath) -> HttpResult {
|
||||||
|
Ok(HttpResponse::Ok()
|
||||||
|
.json(accommodations_list_service::get_all_of_family(m.family_id()).await?))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the information of a single accommodation
|
||||||
|
pub async fn get_single(m: FamilyAndAccommodationInPath) -> HttpResult {
|
||||||
|
Ok(HttpResponse::Ok().json(&m.to_accommodation()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update an accommodation
|
||||||
|
pub async fn update(
|
||||||
|
m: FamilyAndAccommodationInPath,
|
||||||
|
req: web::Json<AccommodationRequest>,
|
||||||
|
_admin: FamilyInPathWithAdminMembership,
|
||||||
|
) -> HttpResult {
|
||||||
|
let mut accommodation = m.to_accommodation();
|
||||||
|
|
||||||
|
if let Err(e) = req.0.to_accommodation(&mut accommodation).await {
|
||||||
|
log::error!("Failed to parse accommodation information! {e}");
|
||||||
|
return Ok(HttpResponse::BadRequest().body(e.to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
accommodations_list_service::update(&mut accommodation).await?;
|
||||||
|
|
||||||
|
Ok(HttpResponse::Accepted().finish())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete an accommodation
|
||||||
|
pub async fn delete(
|
||||||
|
m: FamilyAndAccommodationInPath,
|
||||||
|
_admin: FamilyInPathWithAdminMembership,
|
||||||
|
) -> HttpResult {
|
||||||
|
accommodations_list_service::delete(&mut m.to_accommodation()).await?;
|
||||||
|
Ok(HttpResponse::Ok().finish())
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
use crate::controllers::HttpResult;
|
||||||
|
use crate::extractors::accommodation_extractor::FamilyAndAccommodationInPath;
|
||||||
|
use crate::extractors::accommodation_reservation_extractor::FamilyAndAccommodationReservationInPath;
|
||||||
|
use crate::extractors::family_extractor::FamilyInPath;
|
||||||
|
use crate::services::accommodations_reservations_service;
|
||||||
|
use actix_web::HttpResponse;
|
||||||
|
|
||||||
|
/// Get the reservations for a given accommodation
|
||||||
|
pub async fn get_accommodation_reservations(a: FamilyAndAccommodationInPath) -> HttpResult {
|
||||||
|
Ok(HttpResponse::Ok()
|
||||||
|
.json(accommodations_reservations_service::get_all_of_accommodation(a.id()).await?))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the full list of accommodations reservations for a family
|
||||||
|
pub async fn full_list(m: FamilyInPath) -> HttpResult {
|
||||||
|
Ok(HttpResponse::Ok()
|
||||||
|
.json(accommodations_reservations_service::get_all_of_family(m.family_id()).await?))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a single accommodation reservation
|
||||||
|
pub async fn get_single(m: FamilyAndAccommodationReservationInPath) -> HttpResult {
|
||||||
|
Ok(HttpResponse::Ok().json(m.to_reservation()))
|
||||||
|
}
|
||||||
@@ -80,6 +80,7 @@ struct RichFamilyInfo {
|
|||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
membership: FamilyMembership,
|
membership: FamilyMembership,
|
||||||
enable_genealogy: bool,
|
enable_genealogy: bool,
|
||||||
|
enable_accommodations: bool,
|
||||||
disable_couple_photos: bool,
|
disable_couple_photos: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,6 +91,7 @@ pub async fn single_info(f: FamilyInPath) -> HttpResult {
|
|||||||
Ok(HttpResponse::Ok().json(RichFamilyInfo {
|
Ok(HttpResponse::Ok().json(RichFamilyInfo {
|
||||||
membership,
|
membership,
|
||||||
enable_genealogy: family.enable_genealogy,
|
enable_genealogy: family.enable_genealogy,
|
||||||
|
enable_accommodations: family.enable_accommodations,
|
||||||
disable_couple_photos: family.disable_couple_photos,
|
disable_couple_photos: family.disable_couple_photos,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -105,6 +107,7 @@ pub async fn leave(f: FamilyInPath) -> HttpResult {
|
|||||||
pub struct UpdateFamilyBody {
|
pub struct UpdateFamilyBody {
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
enable_genealogy: Option<bool>,
|
enable_genealogy: Option<bool>,
|
||||||
|
enable_accommodations: Option<bool>,
|
||||||
disable_couple_photos: Option<bool>,
|
disable_couple_photos: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,6 +130,10 @@ pub async fn update(
|
|||||||
family.enable_genealogy = enable_genealogy;
|
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 {
|
if let Some(disable_couple_photos) = req.disable_couple_photos {
|
||||||
family.disable_couple_photos = disable_couple_photos;
|
family.disable_couple_photos = disable_couple_photos;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ use actix_web::HttpResponse;
|
|||||||
use std::fmt::{Debug, Display, Formatter};
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
use zip::result::ZipError;
|
use zip::result::ZipError;
|
||||||
|
|
||||||
|
pub mod accommodations_list_controller;
|
||||||
|
pub mod accommodations_reservations_controller;
|
||||||
pub mod auth_controller;
|
pub mod auth_controller;
|
||||||
pub mod couples_controller;
|
pub mod couples_controller;
|
||||||
pub mod data_controller;
|
pub mod data_controller;
|
||||||
|
|||||||
83
geneit_backend/src/extractors/accommodation_extractor.rs
Normal file
83
geneit_backend/src/extractors/accommodation_extractor.rs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
use crate::extractors::family_extractor::FamilyInPath;
|
||||||
|
use crate::models::{Accommodation, AccommodationID, FamilyID, Membership};
|
||||||
|
use crate::services::accommodations_list_service;
|
||||||
|
use actix_web::dev::Payload;
|
||||||
|
use actix_web::{FromRequest, HttpRequest};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
enum AccommodationExtractorErr {
|
||||||
|
#[error("Accommodation {0:?} does not belong to family {1:?}!")]
|
||||||
|
AccommodationNotInFamily(AccommodationID, FamilyID),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct FamilyAndAccommodationInPath(Membership, Accommodation);
|
||||||
|
|
||||||
|
impl FamilyAndAccommodationInPath {
|
||||||
|
async fn load_accommodation_from_path(
|
||||||
|
family: FamilyInPath,
|
||||||
|
accommodation_id: AccommodationID,
|
||||||
|
) -> anyhow::Result<Self> {
|
||||||
|
let accommodation = accommodations_list_service::get_by_id(accommodation_id).await?;
|
||||||
|
if accommodation.family_id() != family.family_id() {
|
||||||
|
return Err(AccommodationExtractorErr::AccommodationNotInFamily(
|
||||||
|
accommodation.id(),
|
||||||
|
family.family_id(),
|
||||||
|
)
|
||||||
|
.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Self(family.into(), accommodation))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for FamilyAndAccommodationInPath {
|
||||||
|
type Target = Accommodation;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FamilyAndAccommodationInPath {
|
||||||
|
pub fn membership(&self) -> &Membership {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_accommodation(self) -> Accommodation {
|
||||||
|
self.1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct AccommodationIDInPath {
|
||||||
|
accommodation_id: AccommodationID,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromRequest for FamilyAndAccommodationInPath {
|
||||||
|
type Error = actix_web::Error;
|
||||||
|
type Future = futures_util::future::LocalBoxFuture<'static, Result<Self, Self::Error>>;
|
||||||
|
|
||||||
|
fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future {
|
||||||
|
let req = req.clone();
|
||||||
|
Box::pin(async move {
|
||||||
|
let family = FamilyInPath::extract(&req).await?;
|
||||||
|
|
||||||
|
let accommodation_id = actix_web::web::Path::<AccommodationIDInPath>::from_request(
|
||||||
|
&req,
|
||||||
|
&mut Payload::None,
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
.accommodation_id;
|
||||||
|
|
||||||
|
Self::load_accommodation_from_path(family, accommodation_id)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
log::error!("Failed to extract accommodation ID from URL! {}", e);
|
||||||
|
actix_web::error::ErrorNotFound("Could not fetch accommodation information!")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
use crate::extractors::family_extractor::FamilyInPath;
|
||||||
|
use crate::models::{
|
||||||
|
Accommodation, AccommodationReservation, AccommodationReservationID, FamilyID, Membership,
|
||||||
|
};
|
||||||
|
use crate::services::{accommodations_list_service, accommodations_reservations_service};
|
||||||
|
use actix_web::dev::Payload;
|
||||||
|
use actix_web::{FromRequest, HttpRequest};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::fmt::Debug;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
enum AccommodationReservationExtractorErr {
|
||||||
|
#[error("Accommodation reservation {0:?} does not belong to family {1:?}!")]
|
||||||
|
AccommodationNotInFamily(AccommodationReservationID, FamilyID),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct FamilyAndAccommodationReservationInPath(
|
||||||
|
Membership,
|
||||||
|
Accommodation,
|
||||||
|
AccommodationReservation,
|
||||||
|
);
|
||||||
|
|
||||||
|
impl FamilyAndAccommodationReservationInPath {
|
||||||
|
async fn load_accommodation_reservation_from_path(
|
||||||
|
family: FamilyInPath,
|
||||||
|
reservation_id: AccommodationReservationID,
|
||||||
|
) -> anyhow::Result<Self> {
|
||||||
|
let reservation = accommodations_reservations_service::get_by_id(reservation_id).await?;
|
||||||
|
let accommodation =
|
||||||
|
accommodations_list_service::get_by_id(reservation.accommodation_id()).await?;
|
||||||
|
|
||||||
|
if accommodation.family_id() != family.family_id()
|
||||||
|
|| reservation.family_id() != family.family_id()
|
||||||
|
{
|
||||||
|
return Err(
|
||||||
|
AccommodationReservationExtractorErr::AccommodationNotInFamily(
|
||||||
|
reservation.id(),
|
||||||
|
family.family_id(),
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Self(family.into(), accommodation, reservation))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for FamilyAndAccommodationReservationInPath {
|
||||||
|
type Target = AccommodationReservation;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FamilyAndAccommodationReservationInPath {
|
||||||
|
pub fn membership(&self) -> &Membership {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_accommodation(self) -> Accommodation {
|
||||||
|
self.1
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_reservation(self) -> AccommodationReservation {
|
||||||
|
self.2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct ReservationIDInPath {
|
||||||
|
reservation_id: AccommodationReservationID,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromRequest for FamilyAndAccommodationReservationInPath {
|
||||||
|
type Error = actix_web::Error;
|
||||||
|
type Future = futures_util::future::LocalBoxFuture<'static, Result<Self, Self::Error>>;
|
||||||
|
|
||||||
|
fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future {
|
||||||
|
let req = req.clone();
|
||||||
|
Box::pin(async move {
|
||||||
|
let family = FamilyInPath::extract(&req).await?;
|
||||||
|
|
||||||
|
let reservation_id =
|
||||||
|
actix_web::web::Path::<ReservationIDInPath>::from_request(&req, &mut Payload::None)
|
||||||
|
.await?
|
||||||
|
.reservation_id;
|
||||||
|
|
||||||
|
Self::load_accommodation_reservation_from_path(family, reservation_id)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
log::error!("Failed to extract accommodation ID from URL! {}", e);
|
||||||
|
actix_web::error::ErrorNotFound("Could not fetch accommodation information!")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
pub mod accommodation_extractor;
|
||||||
|
pub mod accommodation_reservation_extractor;
|
||||||
pub mod couple_extractor;
|
pub mod couple_extractor;
|
||||||
pub mod family_extractor;
|
pub mod family_extractor;
|
||||||
pub mod member_extractor;
|
pub mod member_extractor;
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ use actix_web::{web, App, HttpServer};
|
|||||||
use geneit_backend::app_config::AppConfig;
|
use geneit_backend::app_config::AppConfig;
|
||||||
use geneit_backend::connections::{db_connection, s3_connection};
|
use geneit_backend::connections::{db_connection, s3_connection};
|
||||||
use geneit_backend::controllers::{
|
use geneit_backend::controllers::{
|
||||||
auth_controller, couples_controller, data_controller, families_controller, members_controller,
|
accommodations_list_controller, accommodations_reservations_controller, auth_controller,
|
||||||
|
couples_controller, data_controller, families_controller, members_controller,
|
||||||
photos_controller, server_controller, users_controller,
|
photos_controller, server_controller, users_controller,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -204,6 +205,50 @@ async fn main() -> std::io::Result<()> {
|
|||||||
"/family/{id}/genealogy/data/import",
|
"/family/{id}/genealogy/data/import",
|
||||||
web::put().to(data_controller::import_family),
|
web::put().to(data_controller::import_family),
|
||||||
)
|
)
|
||||||
|
// [ACCOMODATIONS] List controller
|
||||||
|
.route(
|
||||||
|
"/family/{id}/accommodations/list/create",
|
||||||
|
web::post().to(accommodations_list_controller::create),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/family/{id}/accommodations/list/list",
|
||||||
|
web::get().to(accommodations_list_controller::get_full_list),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/family/{id}/accommodations/list/{accommodation_id}",
|
||||||
|
web::get().to(accommodations_list_controller::get_single),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/family/{id}/accommodations/list/{accommodation_id}",
|
||||||
|
web::put().to(accommodations_list_controller::update),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/family/{id}/accommodations/list/{accommodation_id}",
|
||||||
|
web::delete().to(accommodations_list_controller::delete),
|
||||||
|
)
|
||||||
|
// [ACCOMODATIONS] Reservations controller
|
||||||
|
.route(
|
||||||
|
"/family/{id}/accommodations/reservations/accommodation/{accommodation_id}",
|
||||||
|
web::get()
|
||||||
|
.to(accommodations_reservations_controller::get_accommodation_reservations),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/family/{id}/accommodations/reservations/full_list",
|
||||||
|
web::get().to(accommodations_reservations_controller::full_list),
|
||||||
|
)
|
||||||
|
// TODO : create
|
||||||
|
.route(
|
||||||
|
"/family/{id}/accommodations/reservation/{reservation_id}",
|
||||||
|
web::get().to(accommodations_reservations_controller::get_single),
|
||||||
|
)
|
||||||
|
// TODO : update
|
||||||
|
// TODO : delete
|
||||||
|
// TODO : validate or reject
|
||||||
|
// [ACCOMMODATIONS] Calendars controller
|
||||||
|
// TODO : create
|
||||||
|
// TODO : list
|
||||||
|
// TODO : delete
|
||||||
|
// TODO : anonymous URL access
|
||||||
// Photos controller
|
// Photos controller
|
||||||
.route(
|
.route(
|
||||||
"/photo/{id}",
|
"/photo/{id}",
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
use crate::app_config::AppConfig;
|
use crate::app_config::AppConfig;
|
||||||
use crate::schema::{couples, families, members, memberships, photos, users};
|
use crate::schema::{
|
||||||
|
accommodations_list, accommodations_reservations, couples, families, members, memberships,
|
||||||
|
photos, users,
|
||||||
|
};
|
||||||
use crate::utils::crypt_utils::sha256;
|
use crate::utils::crypt_utils::sha256;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
|
|
||||||
@@ -66,6 +69,7 @@ pub struct Family {
|
|||||||
pub invitation_code: String,
|
pub invitation_code: String,
|
||||||
pub disable_couple_photos: bool,
|
pub disable_couple_photos: bool,
|
||||||
pub enable_genealogy: bool,
|
pub enable_genealogy: bool,
|
||||||
|
pub enable_accommodations: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Family {
|
impl Family {
|
||||||
@@ -308,7 +312,7 @@ pub struct NewMember {
|
|||||||
pub time_update: i64,
|
pub time_update: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Member ID holder
|
/// Couple ID holder
|
||||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, Eq, PartialEq, Hash)]
|
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, Eq, PartialEq, Hash)]
|
||||||
pub struct CoupleID(pub i32);
|
pub struct CoupleID(pub i32);
|
||||||
|
|
||||||
@@ -441,3 +445,81 @@ pub struct NewCouple {
|
|||||||
pub time_create: i64,
|
pub time_create: i64,
|
||||||
pub time_update: i64,
|
pub time_update: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Accommodation ID holder
|
||||||
|
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, Eq, PartialEq, Hash)]
|
||||||
|
pub struct AccommodationID(pub i32);
|
||||||
|
|
||||||
|
#[derive(Queryable, Debug, serde::Serialize)]
|
||||||
|
pub struct Accommodation {
|
||||||
|
id: i32,
|
||||||
|
family_id: i32,
|
||||||
|
time_create: i64,
|
||||||
|
pub time_update: i64,
|
||||||
|
pub name: String,
|
||||||
|
pub need_validation: bool,
|
||||||
|
pub description: Option<String>,
|
||||||
|
pub open_to_reservations: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Accommodation {
|
||||||
|
pub fn id(&self) -> AccommodationID {
|
||||||
|
AccommodationID(self.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn family_id(&self) -> FamilyID {
|
||||||
|
FamilyID(self.family_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable)]
|
||||||
|
#[diesel(table_name = accommodations_list)]
|
||||||
|
pub struct NewAccommodation {
|
||||||
|
pub family_id: i32,
|
||||||
|
pub name: String,
|
||||||
|
pub time_create: i64,
|
||||||
|
pub time_update: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Accommodation reservation ID holder
|
||||||
|
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, Eq, PartialEq, Hash)]
|
||||||
|
pub struct AccommodationReservationID(pub i32);
|
||||||
|
|
||||||
|
#[derive(Queryable, Debug, serde::Serialize)]
|
||||||
|
pub struct AccommodationReservation {
|
||||||
|
id: i32,
|
||||||
|
family_id: i32,
|
||||||
|
accommodation_id: i32,
|
||||||
|
user_id: i32,
|
||||||
|
time_create: i64,
|
||||||
|
pub time_update: i64,
|
||||||
|
pub reservation_start: i64,
|
||||||
|
pub reservation_end: i64,
|
||||||
|
pub validated: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AccommodationReservation {
|
||||||
|
pub fn id(&self) -> AccommodationReservationID {
|
||||||
|
AccommodationReservationID(self.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn accommodation_id(&self) -> AccommodationID {
|
||||||
|
AccommodationID(self.accommodation_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn family_id(&self) -> FamilyID {
|
||||||
|
FamilyID(self.family_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable)]
|
||||||
|
#[diesel(table_name = accommodations_reservations)]
|
||||||
|
pub struct NewAccommodationReservation {
|
||||||
|
pub family_id: i32,
|
||||||
|
pub accommodation_id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
pub time_create: i64,
|
||||||
|
pub time_update: i64,
|
||||||
|
pub reservation_start: i64,
|
||||||
|
pub reservation_end: i64,
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,33 @@
|
|||||||
// @generated automatically by Diesel CLI.
|
// @generated automatically by Diesel CLI.
|
||||||
|
|
||||||
|
diesel::table! {
|
||||||
|
accommodations_list (id) {
|
||||||
|
id -> Int4,
|
||||||
|
family_id -> Int4,
|
||||||
|
time_create -> Int8,
|
||||||
|
time_update -> Int8,
|
||||||
|
#[max_length = 50]
|
||||||
|
name -> Varchar,
|
||||||
|
need_validation -> Bool,
|
||||||
|
description -> Nullable<Text>,
|
||||||
|
open_to_reservations -> Bool,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
diesel::table! {
|
||||||
|
accommodations_reservations (id) {
|
||||||
|
id -> Int4,
|
||||||
|
family_id -> Int4,
|
||||||
|
accommodation_id -> Int4,
|
||||||
|
user_id -> Int4,
|
||||||
|
time_create -> Int8,
|
||||||
|
time_update -> Int8,
|
||||||
|
reservation_start -> Int8,
|
||||||
|
reservation_end -> Int8,
|
||||||
|
validated -> Nullable<Bool>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
couples (id) {
|
couples (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
@@ -30,6 +58,7 @@ diesel::table! {
|
|||||||
invitation_code -> Varchar,
|
invitation_code -> Varchar,
|
||||||
disable_couple_photos -> Bool,
|
disable_couple_photos -> Bool,
|
||||||
enable_genealogy -> Bool,
|
enable_genealogy -> Bool,
|
||||||
|
enable_accommodations -> Bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +148,10 @@ diesel::table! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diesel::joinable!(accommodations_list -> families (family_id));
|
||||||
|
diesel::joinable!(accommodations_reservations -> accommodations_list (accommodation_id));
|
||||||
|
diesel::joinable!(accommodations_reservations -> families (family_id));
|
||||||
|
diesel::joinable!(accommodations_reservations -> users (user_id));
|
||||||
diesel::joinable!(couples -> families (family_id));
|
diesel::joinable!(couples -> families (family_id));
|
||||||
diesel::joinable!(couples -> photos (photo_id));
|
diesel::joinable!(couples -> photos (photo_id));
|
||||||
diesel::joinable!(members -> families (family_id));
|
diesel::joinable!(members -> families (family_id));
|
||||||
@@ -127,6 +160,8 @@ diesel::joinable!(memberships -> families (family_id));
|
|||||||
diesel::joinable!(memberships -> users (user_id));
|
diesel::joinable!(memberships -> users (user_id));
|
||||||
|
|
||||||
diesel::allow_tables_to_appear_in_same_query!(
|
diesel::allow_tables_to_appear_in_same_query!(
|
||||||
|
accommodations_list,
|
||||||
|
accommodations_reservations,
|
||||||
couples,
|
couples,
|
||||||
families,
|
families,
|
||||||
members,
|
members,
|
||||||
|
|||||||
102
geneit_backend/src/services/accommodations_list_service.rs
Normal file
102
geneit_backend/src/services/accommodations_list_service.rs
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
use crate::connections::db_connection;
|
||||||
|
use crate::models::{Accommodation, AccommodationID, FamilyID, NewAccommodation};
|
||||||
|
use crate::schema::accommodations_list;
|
||||||
|
use crate::utils::time_utils::time;
|
||||||
|
use diesel::prelude::*;
|
||||||
|
|
||||||
|
/// Create a new accommodation
|
||||||
|
pub async fn create(family_id: FamilyID) -> anyhow::Result<Accommodation> {
|
||||||
|
db_connection::execute(|conn| {
|
||||||
|
let res: Accommodation = diesel::insert_into(accommodations_list::table)
|
||||||
|
.values(&NewAccommodation {
|
||||||
|
family_id: family_id.0,
|
||||||
|
name: "".to_string(),
|
||||||
|
time_create: time() as i64,
|
||||||
|
time_update: time() as i64,
|
||||||
|
})
|
||||||
|
.get_result(conn)?;
|
||||||
|
|
||||||
|
Ok(res)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the information of an accommodation
|
||||||
|
pub async fn get_by_id(id: AccommodationID) -> anyhow::Result<Accommodation> {
|
||||||
|
db_connection::execute(|conn| {
|
||||||
|
accommodations_list::table
|
||||||
|
.filter(accommodations_list::dsl::id.eq(id.0))
|
||||||
|
.first(conn)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get all the accommodations of a family
|
||||||
|
pub async fn get_all_of_family(id: FamilyID) -> anyhow::Result<Vec<Accommodation>> {
|
||||||
|
db_connection::execute(|conn| {
|
||||||
|
accommodations_list::table
|
||||||
|
.filter(accommodations_list::dsl::family_id.eq(id.0))
|
||||||
|
.get_results(conn)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check whether accommodation with a given id exists or not
|
||||||
|
pub async fn exists(
|
||||||
|
family_id: FamilyID,
|
||||||
|
accommodation_id: AccommodationID,
|
||||||
|
) -> anyhow::Result<bool> {
|
||||||
|
db_connection::execute(|conn| {
|
||||||
|
let count: i64 = accommodations_list::table
|
||||||
|
.filter(
|
||||||
|
accommodations_list::id
|
||||||
|
.eq(accommodation_id.0)
|
||||||
|
.and(accommodations_list::family_id.eq(family_id.0)),
|
||||||
|
)
|
||||||
|
.count()
|
||||||
|
.get_result(conn)?;
|
||||||
|
|
||||||
|
Ok(count != 0)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the information of an accommodation
|
||||||
|
pub async fn update(accommodation: &mut Accommodation) -> anyhow::Result<()> {
|
||||||
|
accommodation.time_update = time() as i64;
|
||||||
|
|
||||||
|
db_connection::execute(|conn| {
|
||||||
|
diesel::update(
|
||||||
|
accommodations_list::dsl::accommodations_list
|
||||||
|
.filter(accommodations_list::dsl::id.eq(accommodation.id().0)),
|
||||||
|
)
|
||||||
|
.set((
|
||||||
|
accommodations_list::dsl::time_update.eq(accommodation.time_update),
|
||||||
|
accommodations_list::dsl::name.eq(accommodation.name.to_string()),
|
||||||
|
accommodations_list::dsl::need_validation.eq(accommodation.need_validation),
|
||||||
|
accommodations_list::dsl::description.eq(accommodation.description.clone()),
|
||||||
|
accommodations_list::dsl::open_to_reservations.eq(accommodation.open_to_reservations),
|
||||||
|
))
|
||||||
|
.execute(conn)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete an accommodation
|
||||||
|
pub async fn delete(accommodation: &mut Accommodation) -> anyhow::Result<()> {
|
||||||
|
// Remove the accommodation
|
||||||
|
db_connection::execute(|conn| {
|
||||||
|
diesel::delete(
|
||||||
|
accommodations_list::dsl::accommodations_list
|
||||||
|
.filter(accommodations_list::dsl::id.eq(accommodation.id().0)),
|
||||||
|
)
|
||||||
|
.execute(conn)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete all the accommodations of a family
|
||||||
|
pub async fn delete_all_family(family_id: FamilyID) -> anyhow::Result<()> {
|
||||||
|
for mut m in get_all_of_family(family_id).await? {
|
||||||
|
delete(&mut m).await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
use crate::connections::db_connection;
|
||||||
|
use crate::models::{
|
||||||
|
AccommodationID, AccommodationReservation, AccommodationReservationID, FamilyID,
|
||||||
|
};
|
||||||
|
use crate::schema::accommodations_reservations;
|
||||||
|
use diesel::prelude::*;
|
||||||
|
|
||||||
|
/// Get all the reservations of an accommodation
|
||||||
|
pub async fn get_all_of_accommodation(
|
||||||
|
id: AccommodationID,
|
||||||
|
) -> anyhow::Result<Vec<AccommodationReservation>> {
|
||||||
|
db_connection::execute(|conn| {
|
||||||
|
accommodations_reservations::table
|
||||||
|
.filter(accommodations_reservations::dsl::accommodation_id.eq(id.0))
|
||||||
|
.get_results(conn)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get all the reservations of a family
|
||||||
|
pub async fn get_all_of_family(id: FamilyID) -> anyhow::Result<Vec<AccommodationReservation>> {
|
||||||
|
db_connection::execute(|conn| {
|
||||||
|
accommodations_reservations::table
|
||||||
|
.filter(accommodations_reservations::dsl::family_id.eq(id.0))
|
||||||
|
.get_results(conn)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a single accommodation reservation by its id
|
||||||
|
pub async fn get_by_id(id: AccommodationReservationID) -> anyhow::Result<AccommodationReservation> {
|
||||||
|
db_connection::execute(|conn| {
|
||||||
|
accommodations_reservations::table
|
||||||
|
.filter(accommodations_reservations::dsl::id.eq(id.0))
|
||||||
|
.get_result(conn)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -5,7 +5,9 @@ use crate::models::{
|
|||||||
Family, FamilyID, FamilyMembership, Membership, NewFamily, NewMembership, UserID,
|
Family, FamilyID, FamilyMembership, Membership, NewFamily, NewMembership, UserID,
|
||||||
};
|
};
|
||||||
use crate::schema::{families, memberships};
|
use crate::schema::{families, memberships};
|
||||||
use crate::services::{couples_service, members_service, users_service};
|
use crate::services::{
|
||||||
|
accommodations_list_service, couples_service, members_service, users_service,
|
||||||
|
};
|
||||||
use crate::utils::string_utils::rand_str;
|
use crate::utils::string_utils::rand_str;
|
||||||
use crate::utils::time_utils::time;
|
use crate::utils::time_utils::time;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
@@ -175,6 +177,7 @@ pub async fn update_family(family: &Family) -> anyhow::Result<()> {
|
|||||||
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::enable_genealogy.eq(family.enable_genealogy),
|
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),
|
families::dsl::disable_couple_photos.eq(family.disable_couple_photos),
|
||||||
))
|
))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
@@ -185,6 +188,9 @@ pub async fn update_family(family: &Family) -> anyhow::Result<()> {
|
|||||||
|
|
||||||
/// Delete a family
|
/// Delete a family
|
||||||
pub async fn delete_family(family_id: FamilyID) -> anyhow::Result<()> {
|
pub async fn delete_family(family_id: FamilyID) -> anyhow::Result<()> {
|
||||||
|
// Delete all family accommodations
|
||||||
|
accommodations_list_service::delete_all_family(family_id).await?;
|
||||||
|
|
||||||
// Delete all family couples
|
// Delete all family couples
|
||||||
couples_service::delete_all_family(family_id).await?;
|
couples_service::delete_all_family(family_id).await?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
//! # Backend services
|
//! # Backend services
|
||||||
|
|
||||||
|
pub mod accommodations_list_service;
|
||||||
|
pub mod accommodations_reservations_service;
|
||||||
pub mod couples_service;
|
pub mod couples_service;
|
||||||
pub mod families_service;
|
pub mod families_service;
|
||||||
pub mod login_token_service;
|
pub mod login_token_service;
|
||||||
|
|||||||
Reference in New Issue
Block a user