Can update couple information

This commit is contained in:
2023-08-07 19:28:44 +02:00
parent 4997132bf8
commit ea84c45e8a
3 changed files with 19 additions and 1 deletions

View File

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