Skip to content
Clone

feat(export): add issues issue_event export

zhenyi committed
parent 3d1cc7a commit 33e5af5 Browse files

1 file changed

+57 −0

Added lib/export/issues/issue_event.rs View lib/export/issues/issue_event.rs
@@ -0,0 +1,57 @@
1use db::issue::issue_event_line as event_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}
11
12#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
13pub struct EventView {
14 pub id: Uuid,
15 pub issue_id: Option<Uuid>,
16 pub user_id: Uuid,
17 pub event_type: String,
18 pub comment_id: Option<Uuid>,
19 pub commit_sha: Option<String>,
20 pub old_title: Option<String>,
21 pub new_title: Option<String>,
22 pub old_ref: Option<String>,
23 pub new_ref: Option<String>,
24 pub content: Option<String>,
25 pub created_at: String,
26}
27
28impl From<event_entity::Model> for EventView {
29 fn from(m: event_entity::Model) -> Self {
30 Self {
31 id: m.id,
32 issue_id: m.issue_id,
33 user_id: m.user_id,
34 event_type: m.event_type,
35 comment_id: m.comment_id,
36 commit_sha: m.commit_sha,
37 old_title: m.old_title,
38 new_title: m.new_title,
39 old_ref: m.old_ref,
40 new_ref: m.new_ref,
41 content: m.content,
42 created_at: fmt_ts(m.created_at),
43 }
44 }
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
48pub struct EventPage {
49 pub items: Vec<EventView>,
50 pub total: i64,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
54pub struct ListEventQuery {
55 pub limit: Option<u64>,
56 pub offset: Option<u64>,
57}