Add an accommodations reservations module #188

Merged
pierre merged 81 commits from accomodation_module into master 2024-06-22 21:30:26 +00:00
4 changed files with 43 additions and 2 deletions
Showing only changes of commit 2346c90be8 - Show all commits

View File

@ -1,5 +1,6 @@
ALTER TABLE public.families ALTER TABLE public.families
DROP COLUMN enable_accommodations; DROP COLUMN enable_accommodations;
DROP TABLE IF EXISTS accommodations_reservations_cals_urls;
DROP TABLE IF EXISTS accommodations_reservations; DROP TABLE IF EXISTS accommodations_reservations;
DROP TABLE IF EXISTS accommodations_list; DROP TABLE IF EXISTS accommodations_list;

View File

@ -18,6 +18,9 @@ CREATE TABLE IF NOT EXISTS accommodations_list
open_to_reservations BOOLEAN NOT NULL DEFAULT false open_to_reservations BOOLEAN NOT NULL DEFAULT false
); );
COMMENT ON COLUMN accommodations_list.need_validation is 'true if family admin review is required for validation. False otherwise';
COMMENT ON COLUMN accommodations_list.open_to_reservations is 'true if reservations can be created / updated. False otherwise';
CREATE TABLE IF NOT EXISTS accommodations_reservations CREATE TABLE IF NOT EXISTS accommodations_reservations
( (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
@ -29,4 +32,20 @@ CREATE TABLE IF NOT EXISTS accommodations_reservations
reservation_start BIGINT NOT NULL, reservation_start BIGINT NOT NULL,
reservation_end BIGINT NOT NULL, reservation_end BIGINT NOT NULL,
validated BOOLEAN NULL validated BOOLEAN NULL
); );
COMMENT ON COLUMN accommodations_reservations.validated is 'null if not reviewed yet. true if reservation is accepted. false if reservation is rejected';
CREATE TABLE IF NOT EXISTS accommodations_reservations_cals_urls
(
id SERIAL PRIMARY KEY,
family_id integer NOT NULL REFERENCES families ON DELETE CASCADE,
accommodation_id integer NULL REFERENCES accommodations_list ON DELETE CASCADE,
user_id INTEGER NOT NULL REFERENCES users ON DELETE CASCADE,
name VARCHAR(50) NOT NULL,
token VARCHAR(50) NOT NULL,
time_create BIGINT NOT NULL,
time_used BIGINT NOT NULL
);
COMMENT ON COLUMN accommodations_reservations_cals_urls.accommodation_id is 'null to get reservations of all accommodations. otherwise get the reservations of the specified accommodation only';

View File

@ -158,7 +158,9 @@ pub async fn validate_or_reject(
q: web::Json<ValidateQuery>, q: web::Json<ValidateQuery>,
) -> HttpResult { ) -> HttpResult {
if !m.membership().is_admin { if !m.membership().is_admin {
return Ok(HttpResponse::BadRequest().json("Only a family admin can validate a reservation!")); return Ok(
HttpResponse::BadRequest().json("Only a family admin can validate a reservation!")
);
} }
if m.validated == Some(q.validate) { if m.validated == Some(q.validate) {

View File

@ -28,6 +28,21 @@ diesel::table! {
} }
} }
diesel::table! {
accommodations_reservations_cals_urls (id) {
id -> Int4,
family_id -> Int4,
accommodation_id -> Nullable<Int4>,
user_id -> Int4,
#[max_length = 50]
name -> Varchar,
#[max_length = 50]
token -> Varchar,
time_create -> Int8,
time_used -> Int8,
}
}
diesel::table! { diesel::table! {
couples (id) { couples (id) {
id -> Int4, id -> Int4,
@ -152,6 +167,9 @@ diesel::joinable!(accommodations_list -> families (family_id));
diesel::joinable!(accommodations_reservations -> accommodations_list (accommodation_id)); diesel::joinable!(accommodations_reservations -> accommodations_list (accommodation_id));
diesel::joinable!(accommodations_reservations -> families (family_id)); diesel::joinable!(accommodations_reservations -> families (family_id));
diesel::joinable!(accommodations_reservations -> users (user_id)); diesel::joinable!(accommodations_reservations -> users (user_id));
diesel::joinable!(accommodations_reservations_cals_urls -> accommodations_list (accommodation_id));
diesel::joinable!(accommodations_reservations_cals_urls -> families (family_id));
diesel::joinable!(accommodations_reservations_cals_urls -> 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));
@ -162,6 +180,7 @@ 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_list,
accommodations_reservations, accommodations_reservations,
accommodations_reservations_cals_urls,
couples, couples,
families, families,
members, members,