Add an accommodations reservations module #188

Merged
pierre merged 81 commits from accomodation_module into master 2024-06-22 21:30:26 +00:00
3 changed files with 25 additions and 3 deletions
Showing only changes of commit 1332b001c8 - Show all commits

View File

@ -1,8 +1,15 @@
use crate::controllers::HttpResult; use crate::controllers::HttpResult;
use crate::extractors::accommodation_extractor::FamilyAndAccommodationInPath;
use crate::extractors::family_extractor::FamilyInPath; use crate::extractors::family_extractor::FamilyInPath;
use crate::services::accommodations_reservations_service; use crate::services::accommodations_reservations_service;
use actix_web::HttpResponse; 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 /// Get the full list of accommodations reservations for a family
pub async fn full_list(m: FamilyInPath) -> HttpResult { pub async fn full_list(m: FamilyInPath) -> HttpResult {
Ok(HttpResponse::Ok() Ok(HttpResponse::Ok()

View File

@ -231,7 +231,11 @@ async fn main() -> std::io::Result<()> {
// TODO : get single // TODO : get single
// TODO : update // TODO : update
// TODO : delete // 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( .route(
"/family/{id}/accommodations/reservations/full_list", "/family/{id}/accommodations/reservations/full_list",
web::get().to(accommodations_reservations_controller::full_list), web::get().to(accommodations_reservations_controller::full_list),

View File

@ -1,9 +1,20 @@
use crate::connections::db_connection; use crate::connections::db_connection;
use crate::models::{AccommodationReservation, FamilyID}; use crate::models::{AccommodationID, AccommodationReservation, FamilyID};
use crate::schema::accommodations_reservations; use crate::schema::accommodations_reservations;
use diesel::prelude::*; 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>> { pub async fn get_all_of_family(id: FamilyID) -> anyhow::Result<Vec<AccommodationReservation>> {
db_connection::execute(|conn| { db_connection::execute(|conn| {
accommodations_reservations::table accommodations_reservations::table