Skip to content
Clone

feat(export): add repo subscriber export

zhenyi committed
parent 80a365a commit 49ae4cb Browse files

1 file changed

+47 −0

Added lib/export/repo/subscriber.rs View lib/export/repo/subscriber.rs
@@ -0,0 +1,47 @@
1use db::common::watch_mode::WatchMode;
2use db::repo::repo_watch as watch_entity;
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 SubscriberView {
15 pub user_id: Uuid,
16 pub repo_id: Uuid,
17 pub mode: String,
18 pub created_at: String,
19}
20
21impl From<watch_entity::Model> for SubscriberView {
22 fn from(m: watch_entity::Model) -> Self {
23 Self {
24 user_id: m.user_id,
25 repo_id: m.repo_id,
26 mode: match m.mode {
27 WatchMode::Normal => "normal".to_string(),
28 WatchMode::Watch => "watch".to_string(),
29 WatchMode::Ignore => "ignore".to_string(),
30 WatchMode::NoWatch => "no_watch".to_string(),
31 },
32 created_at: fmt_ts(m.created_at),
33 }
34 }
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
38pub struct SubscriberPage {
39 pub items: Vec<SubscriberView>,
40 pub total: i64,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
44pub struct ListSubscriberQuery {
45 pub page: Option<u64>,
46 pub limit: Option<u64>,
47}