Add DELETE /family/{id} route

This commit is contained in:
2023-06-21 18:15:20 +02:00
parent 2d7bf10fc2
commit 6bbe69d01f
3 changed files with 56 additions and 2 deletions

View File

@ -1,6 +1,6 @@
use crate::constants::StaticConstraints;
use crate::controllers::HttpResult;
use crate::extractors::family_extractor::FamilyInPath;
use crate::extractors::family_extractor::{FamilyInPath, FamilyInPathWithAdminMembership};
use crate::services::login_token_service::LoginToken;
use crate::services::rate_limiter_service::RatedAction;
use crate::services::{families_service, rate_limiter_service};
@ -86,6 +86,14 @@ pub async fn leave(f: FamilyInPath) -> HttpResult {
Ok(HttpResponse::Accepted().finish())
}
/// Delete a family
pub async fn delete(f: FamilyInPathWithAdminMembership) -> HttpResult {
families_service::delete_family(f.family_id()).await?;
log::info!("User {:?} deleted family {:?}", f.user_id(), f.family_id());
Ok(HttpResponse::Accepted().finish())
}
/// Get the list of users who belongs to a family
pub async fn users(f: FamilyInPath) -> HttpResult {
Ok(HttpResponse::Ok().json(families_service::get_memberships_of_family(f.family_id()).await?))