refactor(user): remove notifications types (inlined)
zhenyi committed
Deleted lib/user/features/notifications/types.rs lib/user/features/notifications/types.rs +0 −252
@@ -1,252 +0,0 @@
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 NotificationType {
9 Mention,
10 Reply,
11 Follow,
12 Invite,
13 Assignment,
14 System,
15}
16
17impl From<db::user::user_notifications::NotificationType> for NotificationType {
18 fn from(t: db::user::user_notifications::NotificationType) -> Self {
19 use db::user::user_notifications::NotificationType as Db;
20 match t {
21 Db::Mention => NotificationType::Mention,
22 Db::Reply => NotificationType::Reply,
23 Db::Follow => NotificationType::Follow,
24 Db::Invite => NotificationType::Invite,
25 Db::Assignment => NotificationType::Assignment,
26 Db::System => NotificationType::System,
27 }
28 }
29}
30
31#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
32#[serde(rename_all = "snake_case")]
33pub enum ReportStatus {
34 Open,
35 UnderReview,
36 Resolved,
37 Dismissed,
38}
39
40impl From<db::user::user_reports::ReportStatus> for ReportStatus {
41 fn from(s: db::user::user_reports::ReportStatus) -> Self {
42 use db::user::user_reports::ReportStatus as Db;
43 match s {
44 Db::Open => ReportStatus::Open,
45 Db::UnderReview => ReportStatus::UnderReview,
46 Db::Resolved => ReportStatus::Resolved,
47 Db::Dismissed => ReportStatus::Dismissed,
48 }
49 }
50}
51
52impl From<ReportStatus> for db::user::user_reports::ReportStatus {
53 fn from(s: ReportStatus) -> Self {
54 use db::user::user_reports::ReportStatus as Db;
55 match s {
56 ReportStatus::Open => Db::Open,
57 ReportStatus::UnderReview => Db::UnderReview,
58 ReportStatus::Resolved => Db::Resolved,
59 ReportStatus::Dismissed => Db::Dismissed,
60 }
61 }
62}
63
64#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
65#[serde(rename_all = "snake_case")]
66pub enum ScheduledMessageStatus {
67 Pending,
68 Sent,
69 Cancelled,
70}
71
72impl From<db::user::user_scheduled_messages::ScheduledMessageStatus> for ScheduledMessageStatus {
73 fn from(s: db::user::user_scheduled_messages::ScheduledMessageStatus) -> Self {
74 use db::user::user_scheduled_messages::ScheduledMessageStatus as Db;
75 match s {
76 Db::Pending => ScheduledMessageStatus::Pending,
77 Db::Sent => ScheduledMessageStatus::Sent,
78 Db::Cancelled => ScheduledMessageStatus::Cancelled,
79 }
80 }
81}
82
83impl From<ScheduledMessageStatus> for db::user::user_scheduled_messages::ScheduledMessageStatus {
84 fn from(s: ScheduledMessageStatus) -> Self {
85 use db::user::user_scheduled_messages::ScheduledMessageStatus as Db;
86 match s {
87 ScheduledMessageStatus::Pending => Db::Pending,
88 ScheduledMessageStatus::Sent => Db::Sent,
89 ScheduledMessageStatus::Cancelled => Db::Cancelled,
90 }
91 }
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
95pub struct NotificationView {
96 pub id: Uuid,
97 pub notification_type: NotificationType,
98 pub title: String,
99 pub body: Option<String>,
100 pub actor_uid: Option<Uuid>,
101 pub read_at: Option<String>,
102 pub created_at: String,
103}
104
105impl From<db::user::user_notifications::Model> for NotificationView {
106 fn from(m: db::user::user_notifications::Model) -> Self {
107 Self {
108 id: m.id,
109 notification_type: m.notification_type.into(),
110 title: m.title,
111 body: m.body,
112 actor_uid: m.actor_uid,
113 read_at: m.read_at.map(|t| t.format(&Rfc3339).unwrap_or_default()),
114 created_at: m.created_at.format(&Rfc3339).unwrap_or_default(),
115 }
116 }
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, Default)]
120pub struct ListNotificationsQuery {
121 pub unread_only: Option<bool>,
122 pub notification_type: Option<NotificationType>,
123 #[serde(default = "default_limit")]
124 pub limit: usize,
125 #[serde(default)]
126 pub cursor: Option<uuid::Uuid>,
127}
128
129fn default_limit() -> usize {
130 20
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
134pub struct MarkReadCmd {
135 pub notification_ids: Vec<Uuid>,
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
139pub struct UnreadCountResp {
140 pub count: i64,
141}
142
143#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
144pub struct RecentMentionView {
145 pub id: Uuid,
146 pub channel_id: Uuid,
147 pub message_id: Uuid,
148 pub created_at: String,
149}
150
151impl From<db::user::user_recent_mentions::Model> for RecentMentionView {
152 fn from(m: db::user::user_recent_mentions::Model) -> Self {
153 Self {
154 id: m.id,
155 channel_id: m.channel_id,
156 message_id: m.message_id,
157 created_at: m.created_at.format(&Rfc3339).unwrap_or_default(),
158 }
159 }
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
163pub struct ReportView {
164 pub id: Uuid,
165 pub reporter_uid: Option<Uuid>,
166 pub reported_uid: Uuid,
167 pub reason: String,
168 pub evidence: Option<String>,
169 pub status: ReportStatus,
170 pub resolver_uid: Option<Uuid>,
171 pub resolution_note: Option<String>,
172 pub created_at: String,
173 pub updated_at: String,
174}
175
176impl From<db::user::user_reports::Model> for ReportView {
177 fn from(m: db::user::user_reports::Model) -> Self {
178 Self {
179 id: m.id,
180 reporter_uid: m.reporter_uid,
181 reported_uid: m.reported_uid,
182 reason: m.reason,
183 evidence: m.evidence,
184 status: m.status.into(),
185 resolver_uid: m.resolver_uid,
186 resolution_note: m.resolution_note,
187 created_at: m.created_at.format(&Rfc3339).unwrap_or_default(),
188 updated_at: m.updated_at.format(&Rfc3339).unwrap_or_default(),
189 }
190 }
191}
192
193#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
194pub struct SubmitReportCmd {
195 pub reported_uid: Uuid,
196 pub reason: String,
197 pub evidence: Option<String>,
198}
199
200#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
201pub struct UpdateReportCmd {
202 pub status: ReportStatus,
203 pub resolution_note: Option<String>,
204}
205
206#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
207pub struct SavedMessageView {
208 pub id: Uuid,
209 pub channel_id: Uuid,
210 pub message_id: Uuid,
211 pub saved_at: String,
212}
213
214impl From<db::user::user_saved_messages::Model> for SavedMessageView {
215 fn from(m: db::user::user_saved_messages::Model) -> Self {
216 Self {
217 id: m.id,
218 channel_id: m.channel_id,
219 message_id: m.message_id,
220 saved_at: m.saved_at.format(&Rfc3339).unwrap_or_default(),
221 }
222 }
223}
224
225#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
226pub struct SaveMessageCmd {
227 pub channel_id: Uuid,
228 pub message_id: Uuid,
229}
230
231#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
232pub struct ScheduledMessageView {
233 pub id: Uuid,
234 pub target_channel_id: Uuid,
235 pub payload: String,
236 pub scheduled_at: String,
237 pub status: ScheduledMessageStatus,
238 pub created_at: String,
239}
240
241impl From<db::user::user_scheduled_messages::Model> for ScheduledMessageView {
242 fn from(m: db::user::user_scheduled_messages::Model) -> Self {
243 Self {
244 id: m.id,
245 target_channel_id: m.target_channel_id,
246 payload: m.payload,
247 scheduled_at: m.scheduled_at.format(&Rfc3339).unwrap_or_default(),
248 status: m.status.into(),
249 created_at: m.created_at.format(&Rfc3339).unwrap_or_default(),
250 }
251 }
252}
No newline at end of file