Can update accommodation information
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Pierre HUBERT 2024-05-25 07:57:50 +02:00
parent 9a4da0462a
commit d0d1169c7d
2 changed files with 22 additions and 1 deletions

View File

@ -77,6 +77,24 @@ pub async fn get_single(m: FamilyAndAccommodationInPath) -> HttpResult {
Ok(HttpResponse::Ok().json(&m.to_accommodation()))
}
/// Update an accommodation
pub async fn update(
m: FamilyAndAccommodationInPath,
req: web::Json<AccommodationRequest>,
_admin: FamilyInPathWithAdminMembership,
) -> HttpResult {
let mut accommodation = m.to_accommodation();
if let Err(e) = req.0.to_accommodation(&mut accommodation).await {
log::error!("Failed to parse accommodation information! {e}");
return Ok(HttpResponse::BadRequest().body(e.to_string()));
}
accommodations_list_service::update(&mut accommodation).await?;
Ok(HttpResponse::Accepted().finish())
}
/// Delete an accommodation
pub async fn delete(
m: FamilyAndAccommodationInPath,

View File

@ -218,7 +218,10 @@ async fn main() -> std::io::Result<()> {
"/family/{id}/accommodations/list/{accommodation_id}",
web::get().to(accommodations_list_controller::get_single),
)
// TODO : update
.route(
"/family/{id}/accommodations/list/{accommodation_id}",
web::put().to(accommodations_list_controller::update),
)
.route(
"/family/{id}/accommodations/list/{accommodation_id}",
web::delete().to(accommodations_list_controller::delete),