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