Skip to content
Clone

refactor(space): remove bans types (inlined)

zhenyi committed
parent c7b1233 commit b01a68b Browse files

1 file changed

+0 −75

Deleted lib/space/features/bans/types.rs
@@ -1,75 +0,0 @@
1use serde::{Deserialize, Serialize};
2use time::OffsetDateTime;
3use time::format_description::well_known::Rfc3339;
4use utoipa::ToSchema;
5use uuid::Uuid;
6
7use db::space::space_bans as ban_entity;
8
9fn fmt_ts(ts: OffsetDateTime) -> String {
10 ts.format(&Rfc3339).unwrap_or_default()
11}
12
13fn fmt_ts_opt(ts: Option<OffsetDateTime>) -> Option<String> {
14 ts.map(fmt_ts)
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
18pub struct SpaceBanView {
19 pub space_id: Uuid,
20 pub user_id: Uuid,
21 pub reason: Option<String>,
22 pub banned_by: Uuid,
23 pub created_at: String,
24 pub updated_at: String,
25 pub expires_at: Option<String>,
26 pub allow_agent_join: bool,
27 pub allow_speak: bool,
28 pub allow_push_repo: bool,
29 pub allow_comment_any: bool,
30}
31
32impl From<ban_entity::Model> for SpaceBanView {
33 fn from(b: ban_entity::Model) -> Self {
34 SpaceBanView {
35 space_id: b.space_id,
36 user_id: b.user_id,
37 reason: b.reason,
38 banned_by: b.banned_by,
39 created_at: fmt_ts(b.created_at),
40 updated_at: fmt_ts(b.updated_at),
41 expires_at: fmt_ts_opt(b.expires_at),
42 allow_agent_join: b.allow_agent_join,
43 allow_speak: b.allow_speak,
44 allow_push_repo: b.allow_push_repo,
45 allow_comment_any: b.allow_comment_any,
46 }
47 }
48}
49
50#[derive(Debug, Clone, Deserialize, ToSchema)]
51pub struct CreateBanCmd {
52 pub user_id: Uuid,
53 pub reason: Option<String>,
54 pub expires_at: Option<String>,
55 pub allow_agent_join: Option<bool>,
56 pub allow_speak: Option<bool>,
57 pub allow_push_repo: Option<bool>,
58 pub allow_comment_any: Option<bool>,
59}
60
61#[derive(Debug, Clone, Deserialize, ToSchema)]
62pub struct UpdateBanCmd {
63 pub reason: Option<Option<String>>,
64 pub expires_at: Option<Option<String>>,
65 pub allow_agent_join: Option<bool>,
66 pub allow_speak: Option<bool>,
67 pub allow_push_repo: Option<bool>,
68 pub allow_comment_any: Option<bool>,
69}
70
71#[derive(Debug, Clone, Serialize, ToSchema)]
72pub struct SpaceBanPage {
73 pub items: Vec<SpaceBanView>,
74 pub total: i64,
75}
No newline at end of file