Add PUT /family/{id}/member/{id_member}

This commit is contained in:
Pierre HUBERT 2023-08-05 10:50:18 +02:00
parent e59ed6ed71
commit eaf09135f4
2 changed files with 18 additions and 0 deletions

View File

@ -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<MemberRequest>) -> 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())
}

View File

@ -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()