Can get all the reservations of a given accommodation
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Pierre HUBERT 2024-05-28 21:43:24 +02:00
parent 6e4b6a0499
commit 1332b001c8
3 changed files with 25 additions and 3 deletions

View File

@ -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()

View File

@ -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),

View File

@ -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<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