Add an accommodations reservations module #188

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

View File

@ -146,3 +146,51 @@ pub async fn delete(m: FamilyAndAccommodationReservationInPath) -> HttpResult {
Ok(HttpResponse::Accepted().finish()) Ok(HttpResponse::Accepted().finish())
} }
#[derive(serde::Deserialize)]
pub struct ValidateQuery {
validate: bool,
}
/// Validate or reject a reservation
pub async fn validate_or_reject(
m: FamilyAndAccommodationReservationInPath,
q: web::Json<ValidateQuery>,
) -> HttpResult {
if !m.membership().is_admin {
return Ok(HttpResponse::BadRequest().json("Only an admin can validate a reservation!"));
}
if m.validated == Some(q.validate) {
return Ok(
HttpResponse::AlreadyReported().json("This reservation has already been processed!")
);
}
// In case of re-validation, check that the time is still available
if m.validated == Some(false) && q.validate {
let potential_conflicts =
accommodations_reservations_service::get_reservations_for_time_interval(
m.accommodation_id(),
m.reservation_start as usize,
m.reservation_end as usize,
)
.await?;
if potential_conflicts
.iter()
.any(|a| a.validated != Some(false))
{
return Ok(HttpResponse::Conflict().json(
"This cannot be accepted as it would create a conflict with another reservation!",
));
}
}
// Update reservation validation status
let mut reservation = m.to_reservation();
reservation.validated = Some(q.validate);
accommodations_reservations_service::update(&mut reservation).await?;
Ok(HttpResponse::Accepted().finish())
}

View File

@ -252,7 +252,10 @@ async fn main() -> std::io::Result<()> {
"/family/{id}/accommodations/reservation/{reservation_id}", "/family/{id}/accommodations/reservation/{reservation_id}",
web::delete().to(accommodations_reservations_controller::delete), web::delete().to(accommodations_reservations_controller::delete),
) )
// TODO : validate or reject .route(
"/family/{id}/accommodations/reservation/{reservation_id}/validate",
web::post().to(accommodations_reservations_controller::validate_or_reject),
)
// [ACCOMMODATIONS] Calendars controller // [ACCOMMODATIONS] Calendars controller
// TODO : create // TODO : create
// TODO : list // TODO : list