koprogo_api/application/dto/
notification_dto.rs

1use crate::domain::entities::{
2    Notification, NotificationChannel, NotificationPreference, NotificationPriority,
3    NotificationStatus, NotificationType,
4};
5use chrono::{DateTime, Utc};
6use serde::{Deserialize, Serialize};
7use uuid::Uuid;
8
9/// Notification Response DTO
10#[derive(Debug, Serialize, Deserialize, Clone)]
11pub struct NotificationResponse {
12    pub id: Uuid,
13    pub organization_id: Uuid,
14    pub user_id: Uuid,
15    pub notification_type: NotificationType,
16    pub channel: NotificationChannel,
17    pub priority: NotificationPriority,
18    pub status: NotificationStatus,
19    pub title: String,
20    pub message: String,
21    pub link_url: Option<String>,
22    pub metadata: Option<String>,
23    pub sent_at: Option<DateTime<Utc>>,
24    pub read_at: Option<DateTime<Utc>>,
25    pub created_at: DateTime<Utc>,
26    pub error_message: Option<String>,
27}
28
29impl From<Notification> for NotificationResponse {
30    fn from(notification: Notification) -> Self {
31        Self {
32            id: notification.id,
33            organization_id: notification.organization_id,
34            user_id: notification.user_id,
35            notification_type: notification.notification_type,
36            channel: notification.channel,
37            priority: notification.priority,
38            status: notification.status,
39            title: notification.title,
40            message: notification.message,
41            link_url: notification.link_url,
42            metadata: notification.metadata,
43            sent_at: notification.sent_at,
44            read_at: notification.read_at,
45            created_at: notification.created_at,
46            error_message: notification.error_message,
47        }
48    }
49}
50
51/// Create Notification Request
52#[derive(Debug, Deserialize)]
53pub struct CreateNotificationRequest {
54    pub user_id: Uuid,
55    pub notification_type: NotificationType,
56    pub channel: NotificationChannel,
57    pub priority: NotificationPriority,
58    pub title: String,
59    pub message: String,
60    pub link_url: Option<String>,
61    pub metadata: Option<String>,
62}
63
64/// Mark Notification as Read Request (for in-app only)
65#[derive(Debug, Deserialize)]
66pub struct MarkReadRequest {
67    // Empty - just marks the notification as read
68}
69
70/// Update Notification Preference Request
71#[derive(Debug, Deserialize)]
72pub struct UpdatePreferenceRequest {
73    pub email_enabled: Option<bool>,
74    pub in_app_enabled: Option<bool>,
75    pub push_enabled: Option<bool>,
76}
77
78/// Notification Preference Response DTO
79#[derive(Debug, Serialize, Deserialize, Clone)]
80pub struct NotificationPreferenceResponse {
81    pub id: Uuid,
82    pub user_id: Uuid,
83    pub notification_type: NotificationType,
84    pub email_enabled: bool,
85    pub in_app_enabled: bool,
86    pub push_enabled: bool,
87    pub created_at: DateTime<Utc>,
88    pub updated_at: DateTime<Utc>,
89}
90
91impl From<NotificationPreference> for NotificationPreferenceResponse {
92    fn from(preference: NotificationPreference) -> Self {
93        Self {
94            id: preference.id,
95            user_id: preference.user_id,
96            notification_type: preference.notification_type,
97            email_enabled: preference.email_enabled,
98            in_app_enabled: preference.in_app_enabled,
99            push_enabled: preference.push_enabled,
100            created_at: preference.created_at,
101            updated_at: preference.updated_at,
102        }
103    }
104}
105
106/// Notification Statistics
107#[derive(Debug, Serialize)]
108pub struct NotificationStats {
109    pub total: i64,
110    pub unread: i64,
111    pub pending: i64,
112    pub sent: i64,
113    pub failed: i64,
114}