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

This commit is contained in:
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())
}