Add DELETE /family/{id}/user/{user_id} route

This commit is contained in:
Pierre HUBERT 2023-06-23 15:33:16 +02:00
parent b2c55b537e
commit 378761f6d5
2 changed files with 26 additions and 0 deletions

View File

@ -169,3 +169,25 @@ pub async fn update_membership(
Ok(HttpResponse::Accepted().finish())
}
/// Delete a family membership
pub async fn delete_membership(
f: FamilyInPathWithAdminMembership,
path: web::Path<UserIdInPath>,
) -> HttpResult {
// An admin can not remove his own membership
if path.user_id == f.user_id() {
return Ok(HttpResponse::Conflict().body("You cannot remove your own membership!"));
}
families_service::remove_membership(f.family_id(), path.user_id).await?;
log::info!(
"User {:?} removed the membership of user {:?} in the family {:?}",
f.user_id(),
path.user_id,
f.family_id()
);
Ok(HttpResponse::Accepted().finish())
}

View File

@ -118,6 +118,10 @@ async fn main() -> std::io::Result<()> {
"/family/{id}/user/{user_id}",
web::patch().to(families_controller::update_membership),
)
.route(
"/family/{id}/user/{user_id}",
web::delete().to(families_controller::delete_membership),
)
})
.bind(AppConfig::get().listen_address.as_str())?
.run()