use axum::Json; use axum::extract::{Path, State}; use axum::http::StatusCode; use jwt::extractor::AuthUser; use uuid::Uuid; use crate::error::{IssueError, IssueResult}; use crate::features::IssueService; use crate::features::issue_attachment::{AttachmentView, UploadAttachmentInput, owner_type_from_str}; #[utoipa::path( post, path = "/issues/{channel_id}/attachments/{owner_type}/{owner_id}", tag = "issues", request_body = UploadAttachmentInput, responses((status = 201, description = "Upload attachment", body = AttachmentView)), security(("bearer_auth" = [])) )] pub(crate) async fn handler( State(svc): State, AuthUser { claims }: AuthUser, Path((channel_id, owner_type, owner_id)): Path<(Uuid, String, Uuid)>, Json(input): Json, ) -> IssueResult<(StatusCode, Json)> { let owner_type = owner_type_from_str(&owner_type) .ok_or_else(|| IssueError::BadRequest(format!("invalid owner_type {owner_type}")))?; let view = svc .upload_attachment(claims.sub, channel_id, owner_type, owner_id, input) .await?; Ok((StatusCode::CREATED, Json(view))) }