Skip to content
Clone

feat(issues): add issue_attachment upload handler

zhenyi committed
parent 8496371 commit 64215d4 Browse files

1 file changed

+31 −0

Added lib/issues/handler/issue_attachment/upload.rs View lib/issues/handler/issue_attachment/upload.rs
@@ -0,0 +1,31 @@
1use axum::Json;
2use axum::extract::{Path, State};
3use axum::http::StatusCode;
4use jwt::extractor::AuthUser;
5use uuid::Uuid;
6
7use crate::error::{IssueError, IssueResult};
8use crate::features::IssueService;
9use crate::features::issue_attachment::{AttachmentView, UploadAttachmentInput, owner_type_from_str};
10
11#[utoipa::path(
12 post,
13 path = "/issues/{channel_id}/attachments/{owner_type}/{owner_id}",
14 tag = "issues",
15 request_body = UploadAttachmentInput,
16 responses((status = 201, description = "Upload attachment", body = AttachmentView)),
17 security(("bearer_auth" = []))
18)]
19pub(crate) async fn handler(
20 State(svc): State<IssueService>,
21 AuthUser { claims }: AuthUser,
22 Path((channel_id, owner_type, owner_id)): Path<(Uuid, String, Uuid)>,
23 Json(input): Json<UploadAttachmentInput>,
24) -> IssueResult<(StatusCode, Json<AttachmentView>)> {
25 let owner_type = owner_type_from_str(&owner_type)
26 .ok_or_else(|| IssueError::BadRequest(format!("invalid owner_type {owner_type}")))?;
27 let view = svc
28 .upload_attachment(claims.sub, channel_id, owner_type, owner_id, input)
29 .await?;
30 Ok((StatusCode::CREATED, Json(view)))
31}
No newline at end of file