diff --git a/geneit_backend/src/controllers/accommodations_reservations_controller.rs b/geneit_backend/src/controllers/accommodations_reservations_controller.rs index b3ec476..f76d491 100644 --- a/geneit_backend/src/controllers/accommodations_reservations_controller.rs +++ b/geneit_backend/src/controllers/accommodations_reservations_controller.rs @@ -1,8 +1,15 @@ use crate::controllers::HttpResult; +use crate::extractors::accommodation_extractor::FamilyAndAccommodationInPath; 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() diff --git a/geneit_backend/src/main.rs b/geneit_backend/src/main.rs index 86d5600..8f1ca0e 100644 --- a/geneit_backend/src/main.rs +++ b/geneit_backend/src/main.rs @@ -231,7 +231,11 @@ async fn main() -> std::io::Result<()> { // TODO : get single // TODO : update // TODO : delete - // TODO : list for an accommodation + .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), diff --git a/geneit_backend/src/services/accommodations_reservations_service.rs b/geneit_backend/src/services/accommodations_reservations_service.rs index ef3c257..ca76976 100644 --- a/geneit_backend/src/services/accommodations_reservations_service.rs +++ b/geneit_backend/src/services/accommodations_reservations_service.rs @@ -1,9 +1,20 @@ use crate::connections::db_connection; -use crate::models::{AccommodationReservation, FamilyID}; +use crate::models::{AccommodationID, AccommodationReservation, FamilyID}; use crate::schema::accommodations_reservations; use diesel::prelude::*; -/// Get all the accommodations reservations of a family +/// Get all the reservations of an accommodation +pub async fn get_all_of_accommodation( + id: AccommodationID, +) -> anyhow::Result> { + 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> { db_connection::execute(|conn| { accommodations_reservations::table