Add an accommodations reservations module #188
@ -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()
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user