Can get accommodations reservations of a family

This commit is contained in:
Pierre HUBERT 2024-05-31 22:09:33 +02:00
parent b34959df33
commit 51f8aaccb6
3 changed files with 28 additions and 1 deletions

View File

@ -50,3 +50,11 @@ pub async fn create(a: FamilyInPath, req: web::Json<CreateCalendarQuery>) -> Htt
Ok(HttpResponse::Ok().json(calendar))
}
/// Get the list of calendars of the user
pub async fn get_list(a: FamilyInPath) -> HttpResult {
let users =
accommodations_reservations_calendars_service::get_all_of_user(a.user_id(), a.family_id())
.await?;
Ok(HttpResponse::Ok().json(users))
}

View File

@ -262,7 +262,10 @@ async fn main() -> std::io::Result<()> {
"/family/{id}/accommodations/reservations_calendars/create",
web::post().to(accommodations_reservations_calendars_controller::create),
)
// TODO : list
.route(
"/family/{id}/accommodations/reservations_calendars/list",
web::get().to(accommodations_reservations_calendars_controller::get_list),
)
// TODO : delete
// TODO : anonymous URL access
// Photos controller

View File

@ -33,3 +33,19 @@ pub async fn create(
Ok(res)
})
}
/// Get all the calendars of a user
pub async fn get_all_of_user(
user: UserID,
family: FamilyID,
) -> anyhow::Result<Vec<AccommodationReservationCalendar>> {
db_connection::execute(|conn| {
accommodations_reservations_cals_urls::table
.filter(
accommodations_reservations_cals_urls::dsl::family_id
.eq(family.0)
.and(accommodations_reservations_cals_urls::dsl::user_id.eq(user.0)),
)
.get_results(conn)
})
}