Skip to content
Clone

feat(export): add issues label export

zhenyi committed
parent 0cb4fd4 commit 46962d5 Browse files

1 file changed

+77 −0

Added lib/export/issues/label.rs View lib/export/issues/label.rs
@@ -0,0 +1,77 @@
1use db::issue::issue_label as label_entity;
2use serde::{Deserialize, Serialize};
3use time::OffsetDateTime;
4use time::format_description::well_known::Rfc3339;
5use utoipa::{IntoParams, ToSchema};
6use uuid::Uuid;
7
8fn fmt_ts(ts: OffsetDateTime) -> String {
9 ts.format(&Rfc3339).unwrap_or_default()
10}
11fn fmt_ts_opt(ts: Option<OffsetDateTime>) -> Option<String> {
12 ts.map(fmt_ts)
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
16pub struct LabelView {
17 pub id: Uuid,
18 pub channel_id: Uuid,
19 pub name: String,
20 pub exclusive: bool,
21 pub exclusive_order: i32,
22 pub description: Option<String>,
23 pub color: String,
24 pub is_archived: bool,
25 pub created_at: String,
26 pub updated_at: Option<String>,
27}
28
29impl From<label_entity::Model> for LabelView {
30 fn from(m: label_entity::Model) -> Self {
31 Self {
32 id: m.id,
33 channel_id: m.channel_id,
34 name: m.name,
35 exclusive: m.exclusive,
36 exclusive_order: m.exclusive_order,
37 description: m.description,
38 color: m.color,
39 is_archived: m.is_archived,
40 created_at: fmt_ts(m.created_at),
41 updated_at: fmt_ts_opt(m.updated_at),
42 }
43 }
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
47pub struct LabelPage {
48 pub items: Vec<LabelView>,
49 pub total: i64,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
53pub struct CreateLabelOption {
54 pub name: String,
55 pub color: String,
56 pub exclusive: Option<bool>,
57 pub exclusive_order: Option<i32>,
58 pub description: Option<String>,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
62pub struct UpdateLabelOption {
63 pub name: Option<String>,
64 pub color: Option<String>,
65 pub exclusive: Option<bool>,
66 pub exclusive_order: Option<i32>,
67 pub description: Option<Option<String>>,
68 pub is_archived: Option<bool>,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
72pub struct ListLabelQuery {
73 pub q: Option<String>,
74 pub is_archived: Option<bool>,
75 pub limit: Option<u64>,
76 pub offset: Option<u64>,
77}
No newline at end of file