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 3512fca..bf3bfb7 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,5 +1,6 @@ ALTER TABLE public.families DROP COLUMN enable_accommodations; +DROP TABLE IF EXISTS accommodations_reservations_cals_urls; DROP TABLE IF EXISTS accommodations_reservations; DROP TABLE IF EXISTS accommodations_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 6ce2823..79d45ec 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 @@ -18,6 +18,9 @@ CREATE TABLE IF NOT EXISTS accommodations_list 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 ( id SERIAL PRIMARY KEY, @@ -29,4 +32,20 @@ CREATE TABLE IF NOT EXISTS accommodations_reservations reservation_start BIGINT NOT NULL, reservation_end BIGINT NOT NULL, validated BOOLEAN NULL -); \ No newline at end of file +); + +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'; diff --git a/geneit_backend/src/controllers/accommodations_reservations_controller.rs b/geneit_backend/src/controllers/accommodations_reservations_controller.rs index 16c66f1..bda86ca 100644 --- a/geneit_backend/src/controllers/accommodations_reservations_controller.rs +++ b/geneit_backend/src/controllers/accommodations_reservations_controller.rs @@ -158,7 +158,9 @@ pub async fn validate_or_reject( q: web::Json, ) -> HttpResult { 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) { diff --git a/geneit_backend/src/schema.rs b/geneit_backend/src/schema.rs index 14ad1a2..6f6200d 100644 --- a/geneit_backend/src/schema.rs +++ b/geneit_backend/src/schema.rs @@ -28,6 +28,21 @@ diesel::table! { } } +diesel::table! { + accommodations_reservations_cals_urls (id) { + id -> Int4, + family_id -> Int4, + accommodation_id -> Nullable, + user_id -> Int4, + #[max_length = 50] + name -> Varchar, + #[max_length = 50] + token -> Varchar, + time_create -> Int8, + time_used -> Int8, + } +} + diesel::table! { couples (id) { 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 -> families (family_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 -> photos (photo_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!( accommodations_list, accommodations_reservations, + accommodations_reservations_cals_urls, couples, families, members,