feat(export): add user suspensions export
zhenyi committed
Added lib/export/user/suspensions.rs lib/export/user/suspensions.rs +72 −0 View lib/export/user/suspensions.rs
@@ -0,0 +1,72 @@
1use serde::{Deserialize, Serialize};
2use time::format_description::well_known::Rfc3339;
3use utoipa::ToSchema;
4use uuid::Uuid;
5
6#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
7#[serde(rename_all = "snake_case")]
8pub enum SuspensionType {
9 Temporary,
10 Permanent,
11}
12
13impl From<db::user::user_suspensions::SuspensionType> for SuspensionType {
14 fn from(t: db::user::user_suspensions::SuspensionType) -> Self {
15 match t {
16 db::user::user_suspensions::SuspensionType::Temporary => SuspensionType::Temporary,
17 db::user::user_suspensions::SuspensionType::Permanent => SuspensionType::Permanent,
18 }
19 }
20}
21
22impl From<SuspensionType> for db::user::user_suspensions::SuspensionType {
23 fn from(t: SuspensionType) -> Self {
24 match t {
25 SuspensionType::Temporary => db::user::user_suspensions::SuspensionType::Temporary,
26 SuspensionType::Permanent => db::user::user_suspensions::SuspensionType::Permanent,
27 }
28 }
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
32pub struct SuspensionView {
33 pub id: Uuid,
34 pub user_id: Uuid,
35 pub suspension_type: SuspensionType,
36 pub reason: Option<String>,
37 pub suspended_by: Option<Uuid>,
38 pub starts_at: String,
39 pub ends_at: Option<String>,
40 pub revoked_at: Option<String>,
41 pub revoked_by: Option<Uuid>,
42 pub created_at: String,
43}
44
45impl From<db::user::user_suspensions::Model> for SuspensionView {
46 fn from(m: db::user::user_suspensions::Model) -> Self {
47 Self {
48 id: m.id,
49 user_id: m.user_id,
50 suspension_type: m.suspension_type.into(),
51 reason: m.reason,
52 suspended_by: m.suspended_by,
53 starts_at: m.starts_at.format(&Rfc3339).unwrap_or_default(),
54 ends_at: m.ends_at.map(|t| t.format(&Rfc3339).unwrap_or_default()),
55 revoked_at: m.revoked_at.map(|t| t.format(&Rfc3339).unwrap_or_default()),
56 revoked_by: m.revoked_by,
57 created_at: m.created_at.format(&Rfc3339).unwrap_or_default(),
58 }
59 }
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
63pub struct SuspendCmd {
64 pub suspension_type: SuspensionType,
65 pub reason: Option<String>,
66 pub ends_at: Option<String>,
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
70pub struct RevokeSuspensionCmd {
71 pub reason: Option<String>,
72}
No newline at end of file