feat(issues): add issue_attachment list handler
zhenyi committed
Added lib/issues/handler/issue_attachment/list.rs lib/issues/handler/issue_attachment/list.rs +33 −0 View lib/issues/handler/issue_attachment/list.rs
@@ -0,0 +1,33 @@
1use axum::Json;
2use axum::extract::{Path, Query, State};
3use jwt::extractor::AuthUser;
4use uuid::Uuid;
5
6use crate::error::{IssueError, IssueResult};
7use crate::features::IssueService;
8use crate::features::issue_attachment::{ListAttachmentQuery, owner_type_from_str};
9
10#[utoipa::path(
11 get,
12 path = "/issues/{channel_id}/attachments/{owner_type}/{owner_id}",
13 tag = "issues",
14 params(ListAttachmentQuery),
15 responses((status = 200, description = "List attachments")),
16 security(("bearer_auth" = []))
17)]
18pub(crate) async fn handler(
19 State(svc): State<IssueService>,
20 AuthUser { claims }: AuthUser,
21 Path((channel_id, owner_type, owner_id)): Path<(Uuid, String, Uuid)>,
22 Query(q): Query<ListAttachmentQuery>,
23) -> IssueResult<Json<serde_json::Value>> {
24 let owner_type = owner_type_from_str(&owner_type)
25 .ok_or_else(|| IssueError::BadRequest(format!("invalid owner_type {owner_type}")))?;
26 let page = svc
27 .list_attachments(claims.sub, channel_id, owner_type, owner_id, q)
28 .await?;
29 Ok(Json(serde_json::json!({
30 "items": page.items,
31 "total": page.total,
32 })))
33}
No newline at end of file