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 AdminEmail, 33} 34 35#[derive(Debug, Clone, FromRow)] 36pub struct QueuedNotification { 37 pub id: Uuid, 38 pub user_id: Uuid, 39 pub channel: NotificationChannel, 40 pub notification_type: NotificationType, 41 pub status: NotificationStatus, 42 pub recipient: String, 43 pub subject: Option<String>, 44 pub body: String, 45 pub metadata: Option<serde_json::Value>, 46 pub attempts: i32, 47 pub max_attempts: i32, 48 pub last_error: Option<String>, 49 pub created_at: DateTime<Utc>, 50 pub updated_at: DateTime<Utc>, 51 pub scheduled_for: DateTime<Utc>, 52 pub processed_at: Option<DateTime<Utc>>, 53} 54 55pub struct NewNotification { 56 pub user_id: Uuid, 57 pub channel: NotificationChannel, 58 pub notification_type: NotificationType, 59 pub recipient: String, 60 pub subject: Option<String>, 61 pub body: String, 62 pub metadata: Option<serde_json::Value>, 63} 64 65impl NewNotification { 66 pub fn email( 67 user_id: Uuid, 68 notification_type: NotificationType, 69 recipient: String, 70 subject: String, 71 body: String, 72 ) -> Self { 73 Self { 74 user_id, 75 channel: NotificationChannel::Email, 76 notification_type, 77 recipient, 78 subject: Some(subject), 79 body, 80 metadata: None, 81 } 82 } 83}