Can get the full list of accommodation reservations for a family
This commit is contained in:
parent
d0d1169c7d
commit
936b095d46
@ -0,0 +1,10 @@
|
|||||||
|
use crate::controllers::HttpResult;
|
||||||
|
use crate::extractors::family_extractor::FamilyInPath;
|
||||||
|
use crate::services::accommodations_reservations_service;
|
||||||
|
use actix_web::HttpResponse;
|
||||||
|
|
||||||
|
/// Get the full list of accommodations reservations for a family
|
||||||
|
pub async fn full_list(m: FamilyInPath) -> HttpResult {
|
||||||
|
Ok(HttpResponse::Ok()
|
||||||
|
.json(accommodations_reservations_service::get_all_of_family(m.family_id()).await?))
|
||||||
|
}
|
@ -6,6 +6,7 @@ use std::fmt::{Debug, Display, Formatter};
|
|||||||
use zip::result::ZipError;
|
use zip::result::ZipError;
|
||||||
|
|
||||||
pub mod accommodations_list_controller;
|
pub mod accommodations_list_controller;
|
||||||
|
pub mod accommodations_reservations_controller;
|
||||||
pub mod auth_controller;
|
pub mod auth_controller;
|
||||||
pub mod couples_controller;
|
pub mod couples_controller;
|
||||||
pub mod data_controller;
|
pub mod data_controller;
|
||||||
|
@ -6,9 +6,9 @@ use actix_web::{web, App, HttpServer};
|
|||||||
use geneit_backend::app_config::AppConfig;
|
use geneit_backend::app_config::AppConfig;
|
||||||
use geneit_backend::connections::{db_connection, s3_connection};
|
use geneit_backend::connections::{db_connection, s3_connection};
|
||||||
use geneit_backend::controllers::{
|
use geneit_backend::controllers::{
|
||||||
accommodations_list_controller, auth_controller, couples_controller, data_controller,
|
accommodations_list_controller, accommodations_reservations_controller, auth_controller,
|
||||||
families_controller, members_controller, photos_controller, server_controller,
|
couples_controller, data_controller, families_controller, members_controller,
|
||||||
users_controller,
|
photos_controller, server_controller, users_controller,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
@ -228,9 +228,14 @@ async fn main() -> std::io::Result<()> {
|
|||||||
)
|
)
|
||||||
// [ACCOMODATIONS] Reservations controller
|
// [ACCOMODATIONS] Reservations controller
|
||||||
// TODO : create
|
// TODO : create
|
||||||
|
// TODO : get single
|
||||||
// TODO : update
|
// TODO : update
|
||||||
// TODO : delete
|
// TODO : delete
|
||||||
// TODO : list
|
// TODO : list for an accommodation
|
||||||
|
.route(
|
||||||
|
"/family/{id}/accommodations/reservations/full_list",
|
||||||
|
web::get().to(accommodations_reservations_controller::full_list),
|
||||||
|
)
|
||||||
// TODO : validate or reject
|
// TODO : validate or reject
|
||||||
// Photos controller
|
// Photos controller
|
||||||
.route(
|
.route(
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
use crate::app_config::AppConfig;
|
use crate::app_config::AppConfig;
|
||||||
use crate::schema::{accommodations_list, couples, families, members, memberships, photos, users};
|
use crate::schema::{
|
||||||
|
accommodations_list, accommodations_reservations, couples, families, members, memberships,
|
||||||
|
photos, users,
|
||||||
|
};
|
||||||
use crate::utils::crypt_utils::sha256;
|
use crate::utils::crypt_utils::sha256;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
|
|
||||||
@ -477,3 +480,32 @@ pub struct NewAccommodation {
|
|||||||
pub time_create: i64,
|
pub time_create: i64,
|
||||||
pub time_update: i64,
|
pub time_update: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Accommodation reservation ID holder
|
||||||
|
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, Eq, PartialEq, Hash)]
|
||||||
|
pub struct AccommodationReservationID(pub i32);
|
||||||
|
|
||||||
|
#[derive(Queryable, Debug, serde::Serialize)]
|
||||||
|
pub struct AccommodationReservation {
|
||||||
|
id: i32,
|
||||||
|
family_id: i32,
|
||||||
|
accommodation_id: i32,
|
||||||
|
user_id: i32,
|
||||||
|
time_create: i64,
|
||||||
|
pub time_update: i64,
|
||||||
|
pub reservation_start: i64,
|
||||||
|
pub reservation_end: i64,
|
||||||
|
pub validated: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable)]
|
||||||
|
#[diesel(table_name = accommodations_reservations)]
|
||||||
|
pub struct NewAccommodationReservation {
|
||||||
|
pub family_id: i32,
|
||||||
|
pub accommodation_id: i32,
|
||||||
|
pub user_id: i32,
|
||||||
|
pub time_create: i64,
|
||||||
|
pub time_update: i64,
|
||||||
|
pub reservation_start: i64,
|
||||||
|
pub reservation_end: i64,
|
||||||
|
}
|
||||||
|
@ -29,7 +29,7 @@ pub async fn get_by_id(id: AccommodationID) -> anyhow::Result<Accommodation> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all the couples of an accommodation
|
/// Get all the accommodations of a family
|
||||||
pub async fn get_all_of_family(id: FamilyID) -> anyhow::Result<Vec<Accommodation>> {
|
pub async fn get_all_of_family(id: FamilyID) -> anyhow::Result<Vec<Accommodation>> {
|
||||||
db_connection::execute(|conn| {
|
db_connection::execute(|conn| {
|
||||||
accommodations_list::table
|
accommodations_list::table
|
||||||
@ -57,7 +57,7 @@ pub async fn exists(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the information of a couple
|
/// Update the information of an accommodation
|
||||||
pub async fn update(accommodation: &mut Accommodation) -> anyhow::Result<()> {
|
pub async fn update(accommodation: &mut Accommodation) -> anyhow::Result<()> {
|
||||||
accommodation.time_update = time() as i64;
|
accommodation.time_update = time() as i64;
|
||||||
|
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
use crate::connections::db_connection;
|
||||||
|
use crate::models::{AccommodationReservation, FamilyID};
|
||||||
|
use crate::schema::accommodations_reservations;
|
||||||
|
use diesel::prelude::*;
|
||||||
|
|
||||||
|
/// Get all the accommodations reservations of a family
|
||||||
|
pub async fn get_all_of_family(id: FamilyID) -> anyhow::Result<Vec<AccommodationReservation>> {
|
||||||
|
db_connection::execute(|conn| {
|
||||||
|
accommodations_reservations::table
|
||||||
|
.filter(accommodations_reservations::dsl::family_id.eq(id.0))
|
||||||
|
.get_results(conn)
|
||||||
|
})
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
//! # Backend services
|
//! # Backend services
|
||||||
|
|
||||||
pub mod accommodations_list_service;
|
pub mod accommodations_list_service;
|
||||||
|
pub mod accommodations_reservations_service;
|
||||||
pub mod couples_service;
|
pub mod couples_service;
|
||||||
pub mod families_service;
|
pub mod families_service;
|
||||||
pub mod login_token_service;
|
pub mod login_token_service;
|
||||||
|
Loading…
Reference in New Issue
Block a user