From d0d1169c7d7855e8c7094c18aec516479abe7f2d Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 25 May 2024 07:57:50 +0200 Subject: [PATCH] Can update accommodation information --- .../accommodations_list_controller.rs | 18 ++++++++++++++++++ geneit_backend/src/main.rs | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/geneit_backend/src/controllers/accommodations_list_controller.rs b/geneit_backend/src/controllers/accommodations_list_controller.rs index 45613bc..665bcb2 100644 --- a/geneit_backend/src/controllers/accommodations_list_controller.rs +++ b/geneit_backend/src/controllers/accommodations_list_controller.rs @@ -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, + _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, diff --git a/geneit_backend/src/main.rs b/geneit_backend/src/main.rs index d861667..4dbaa40 100644 --- a/geneit_backend/src/main.rs +++ b/geneit_backend/src/main.rs @@ -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),