From eaf09135f4e7371acedf9e60c703a81814ecd882 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Sat, 5 Aug 2023 10:50:18 +0200 Subject: [PATCH] Add PUT /family/{id}/member/{id_member} --- .../src/controllers/members_controller.rs | 14 ++++++++++++++ geneit_backend/src/main.rs | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/geneit_backend/src/controllers/members_controller.rs b/geneit_backend/src/controllers/members_controller.rs index 103bf09..1f83427 100644 --- a/geneit_backend/src/controllers/members_controller.rs +++ b/geneit_backend/src/controllers/members_controller.rs @@ -252,3 +252,17 @@ pub async fn get_all(f: FamilyInPath) -> HttpResult { pub async fn get_single(m: FamilyAndMemberInPath) -> HttpResult { Ok(HttpResponse::Ok().json(m.to_member())) } + +/// Update a member information +pub async fn update(m: FamilyAndMemberInPath, req: web::Json) -> HttpResult { + let mut member = m.to_member(); + + if let Err(e) = req.0.to_member(&mut member).await { + log::error!("Failed to parse member information {e}!"); + return Ok(HttpResponse::BadRequest().body(e.to_string())); + } + + members_service::update(&mut member).await?; + + Ok(HttpResponse::Accepted().finish()) +} diff --git a/geneit_backend/src/main.rs b/geneit_backend/src/main.rs index 81b211f..4ec6854 100644 --- a/geneit_backend/src/main.rs +++ b/geneit_backend/src/main.rs @@ -135,6 +135,10 @@ async fn main() -> std::io::Result<()> { "/family/{id}/member/{member_id}", web::get().to(members_controller::get_single), ) + .route( + "/family/{id}/member/{member_id}", + web::put().to(members_controller::update), + ) }) .bind(AppConfig::get().listen_address.as_str())? .run()