libomni/types/db/v1/
notification.rs

1use serde::{Deserialize, Serialize};
2use chrono::{DateTime, Utc};
3
4#[derive(Debug, sqlx::FromRow, Serialize, Deserialize)]
5pub struct UserNotification {
6    pub id: i64,
7    pub user_id: i64,
8    pub org_id: Option<i64>,
9    pub app_id: Option<i64>,
10    pub notification_type: String,
11    pub message: String,
12    pub read_status: bool,
13    pub importance: String,
14    pub action_url: Option<String>,
15    pub action_label: Option<String>,
16    pub created_at: DateTime<Utc>,
17    pub expires_at: Option<DateTime<Utc>>,
18}
19
20// Role Notifications
21#[derive(Debug, sqlx::FromRow, Serialize, Deserialize)]
22pub struct RoleNotification {
23    pub id: i64,
24    pub role_id: i64,
25    pub org_id: Option<i64>,
26    pub app_id: Option<i64>,
27    pub notification_type: String,
28    pub message: String,
29    pub importance: String,
30    pub action_url: Option<String>,
31    pub action_label: Option<String>,
32    pub created_at: DateTime<Utc>,
33    pub expires_at: Option<DateTime<Utc>>,
34}
35
36// Notification Acknowledgments
37#[derive(Debug, sqlx::FromRow, Serialize, Deserialize)]
38pub struct NotificationAcknowledgment {
39    pub id: i64,
40    pub user_id: i64,
41    pub notification_id: Option<i64>,
42    pub role_notification_id: Option<i64>,
43    pub acknowledged_at: DateTime<Utc>
44}
45
46/// Represents a comprehensive view of a user's notifications with unread counts.
47/// This is useful for providing notification center overviews.
48#[derive(Debug, Serialize, Deserialize)]
49pub struct NotificationWithCount {
50    /// Direct notifications for the user
51    pub user_notifications: Vec<UserNotification>,
52    /// Role-based notifications applicable to the user
53    pub role_notifications: Vec<RoleNotification>,
54    /// User's acknowledgments of role notifications
55    pub acknowledgments: Vec<NotificationAcknowledgment>,
56    /// Count of unread direct user notifications
57    pub unread_user_count: i64,
58    /// Count of unacknowledged role notifications
59    pub unacknowledged_role_count: i64,
60    /// Total count of unread notifications (user + role)
61    pub total_unread_count: i64
62}
63
64/// Represents a user's notifications including those from their roles.
65/// This combines personal notifications with role-based ones.
66#[derive(Debug, Serialize, Deserialize)]
67pub struct UserNotificationWithRoleNotifications {
68    /// Direct notifications for the user
69    pub user_notifications: Vec<UserNotification>,
70    /// Role-based notifications applicable to the user
71    pub role_notifications: Vec<RoleNotification>,
72    /// User's acknowledgments of role notifications
73    pub acknowledgments: Vec<NotificationAcknowledgment>
74}
75
76#[derive(Debug, sqlx::FromRow, Serialize)]
77pub struct Notification {
78    pub id: i64,
79    pub user_id: Option<i64>,
80    pub org_id: Option<i64>,
81    pub app_id: Option<i64>,
82    pub notification_type: String, // enum: 'info', 'warning', 'error', 'success'
83    pub message: String,
84    pub read_status: bool,
85    pub created_at: DateTime<Utc>,
86}