refactor(issues): remove issue_attachment types (inlined)
zhenyi committed
Deleted lib/issues/features/issue_attachment/types.rs lib/issues/features/issue_attachment/types.rs +0 −71
@@ -1,71 +0,0 @@
1use db::attachment::attachments as att_entity;
2use db::attachment::attachments::OwnerType;
3use serde::{Deserialize, Serialize};
4use time::OffsetDateTime;
5use time::format_description::well_known::Rfc3339;
6use utoipa::{IntoParams, ToSchema};
7use uuid::Uuid;
8
9fn fmt_ts(ts: OffsetDateTime) -> String {
10 ts.format(&Rfc3339).unwrap_or_default()
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
14pub struct AttachmentView {
15 pub id: Uuid,
16 pub owner_type: String,
17 pub owner_id: Uuid,
18 pub filename: String,
19 pub content_type: String,
20 pub size: i64,
21 pub url: String,
22 pub uploaded_by: Option<Uuid>,
23 pub created_at: String,
24}
25
26impl From<att_entity::Model> for AttachmentView {
27 fn from(m: att_entity::Model) -> Self {
28 Self {
29 id: m.id,
30 owner_type: format!("{:?}", m.owner_type),
31 owner_id: m.owner_id,
32 filename: m.filename,
33 content_type: m.content_type,
34 size: m.size,
35 url: m.url,
36 uploaded_by: m.uploaded_by,
37 created_at: fmt_ts(m.created_at),
38 }
39 }
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
43pub struct UploadAttachmentInput {
44 pub filename: String,
45 pub content_type: String,
46 pub data: Vec<u8>,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
50pub struct AttachmentPage {
51 pub items: Vec<AttachmentView>,
52 pub total: i64,
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
56pub struct ListAttachmentQuery {
57 pub limit: Option<u64>,
58 pub offset: Option<u64>,
59}
60
61pub fn owner_type_from_str(s: &str) -> Option<OwnerType> {
62 Some(match s {
63 "issue" | "Issue" => OwnerType::Issue,
64 "comment" | "Comment" => OwnerType::Comment,
65 "release" | "Release" => OwnerType::Release,
66 "chat_message" | "ChatMessage" => OwnerType::ChatMessage,
67 "post" | "Post" => OwnerType::Post,
68 "post_reply" | "PostReply" => OwnerType::PostReply,
69 _ => return None,
70 })
71}