this repo has no description
1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use sqlx::FromRow;
4use uuid::Uuid;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, sqlx::Type, Serialize, Deserialize)]
7#[sqlx(type_name = "notification_channel", rename_all = "lowercase")]
8pub enum NotificationChannel {
9 Email,
10 Discord,
11 Telegram,
12 Signal,
13}
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq, sqlx::Type, Serialize, Deserialize)]
16#[sqlx(type_name = "notification_status", rename_all = "lowercase")]
17pub enum NotificationStatus {
18 Pending,
19 Processing,
20 Sent,
21 Failed,
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, sqlx::Type, Serialize, Deserialize)]
25#[sqlx(type_name = "notification_type", rename_all = "snake_case")]
26pub enum NotificationType {
27 Welcome,
28 EmailVerification,
29 PasswordReset,
30 EmailUpdate,
31 AccountDeletion,
32}
33
34#[derive(Debug, Clone, FromRow)]
35pub struct QueuedNotification {
36 pub id: Uuid,
37 pub user_id: Uuid,
38 pub channel: NotificationChannel,
39 pub notification_type: NotificationType,
40 pub status: NotificationStatus,
41 pub recipient: String,
42 pub subject: Option<String>,
43 pub body: String,
44 pub metadata: Option<serde_json::Value>,
45 pub attempts: i32,
46 pub max_attempts: i32,
47 pub last_error: Option<String>,
48 pub created_at: DateTime<Utc>,
49 pub updated_at: DateTime<Utc>,
50 pub scheduled_for: DateTime<Utc>,
51 pub processed_at: Option<DateTime<Utc>>,
52}
53
54pub struct NewNotification {
55 pub user_id: Uuid,
56 pub channel: NotificationChannel,
57 pub notification_type: NotificationType,
58 pub recipient: String,
59 pub subject: Option<String>,
60 pub body: String,
61 pub metadata: Option<serde_json::Value>,
62}
63
64impl NewNotification {
65 pub fn email(
66 user_id: Uuid,
67 notification_type: NotificationType,
68 recipient: String,
69 subject: String,
70 body: String,
71 ) -> Self {
72 Self {
73 user_id,
74 channel: NotificationChannel::Email,
75 notification_type,
76 recipient,
77 subject: Some(subject),
78 body,
79 metadata: None,
80 }
81 }
82}