Add DELETE /family/{id}/user/{user_id} route
This commit is contained in:
parent
b2c55b537e
commit
378761f6d5
@ -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())
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user