Skip to content
Clone
d5939db
27 lines 1020 B Rust
use axum::extract::{Path, State};
use export::data::{AppResponseData, NoData};
use jwt::extractor::AuthUser;
use uuid::Uuid;
use crate::error::{IssueError, IssueResult};
use crate::features::IssueService;
use crate::features::issue_attachment::owner_type_from_str;
#[utoipa::path(
delete,
path = "/issues/{channel_id}/attachments/{owner_type}/{owner_id}/{att_id}",
tag = "issues",
responses((status = 204, description = "Delete attachment")),
security(("bearer_auth" = []))
)]
pub(crate) async fn handler(
State(svc): State<IssueService>,
AuthUser { claims }: AuthUser,
Path((channel_id, owner_type, owner_id, att_id)): Path<(Uuid, String, Uuid, Uuid)>,
) -> IssueResult<AppResponseData<NoData>> {
let owner_type = owner_type_from_str(&owner_type)
.ok_or_else(|| IssueError::BadRequest(format!("invalid owner_type {owner_type}")))?;
svc.delete_attachment(claims.sub, channel_id, owner_type, owner_id, att_id)
.await?;
Ok(AppResponseData::<NoData>::empty())
}