diff --git a/geneit_backend/src/controllers/couples_controller.rs b/geneit_backend/src/controllers/couples_controller.rs index c9143a8..87dafe7 100644 --- a/geneit_backend/src/controllers/couples_controller.rs +++ b/geneit_backend/src/controllers/couples_controller.rs @@ -130,3 +130,17 @@ pub async fn get_all(m: FamilyInPath) -> HttpResult { pub async fn get_single(m: FamilyAndCoupleInPath) -> HttpResult { Ok(HttpResponse::Ok().json(CoupleAPI::new(m.to_couple()))) } + +/// Update a couple information +pub async fn update(m: FamilyAndCoupleInPath, req: web::Json) -> HttpResult { + let mut couple = m.to_couple(); + + if let Err(e) = req.0.to_couple(&mut couple).await { + log::error!("Failed to parse couple information {e}!"); + return Ok(HttpResponse::BadRequest().body(e.to_string())); + } + + couples_service::update(&mut couple).await?; + + Ok(HttpResponse::Accepted().finish()) +} diff --git a/geneit_backend/src/main.rs b/geneit_backend/src/main.rs index a765a04..c7f30e2 100644 --- a/geneit_backend/src/main.rs +++ b/geneit_backend/src/main.rs @@ -175,6 +175,10 @@ async fn main() -> std::io::Result<()> { "/family/{id}/couple/{couple_id}", web::get().to(couples_controller::get_single), ) + .route( + "/family/{id}/couple/{couple_id}", + web::put().to(couples_controller::update), + ) // Photos controller .route( "/photo/{id}", diff --git a/geneit_backend/src/models.rs b/geneit_backend/src/models.rs index 8341a24..ce27d26 100644 --- a/geneit_backend/src/models.rs +++ b/geneit_backend/src/models.rs @@ -332,7 +332,7 @@ impl CoupleState { } pub fn parse_str(s: &str) -> Option { - serde_json::from_str(s).ok() + serde_json::from_str(&format!("\"{s}\"")).ok() } pub fn states_list() -> Vec {