koprogo_api/application/ports/
notification_repository.rs

1use crate::domain::entities::{Notification, NotificationChannel, NotificationStatus};
2use async_trait::async_trait;
3use uuid::Uuid;
4
5#[async_trait]
6pub trait NotificationRepository: Send + Sync {
7    /// Create a new notification
8    async fn create(&self, notification: &Notification) -> Result<Notification, String>;
9
10    /// Find notification by ID
11    async fn find_by_id(&self, id: Uuid) -> Result<Option<Notification>, String>;
12
13    /// Find notifications by user
14    async fn find_by_user(&self, user_id: Uuid) -> Result<Vec<Notification>, String>;
15
16    /// Find notifications by user and status
17    async fn find_by_user_and_status(
18        &self,
19        user_id: Uuid,
20        status: NotificationStatus,
21    ) -> Result<Vec<Notification>, String>;
22
23    /// Find notifications by user and channel
24    async fn find_by_user_and_channel(
25        &self,
26        user_id: Uuid,
27        channel: NotificationChannel,
28    ) -> Result<Vec<Notification>, String>;
29
30    /// Find unread in-app notifications for user
31    async fn find_unread_by_user(&self, user_id: Uuid) -> Result<Vec<Notification>, String>;
32
33    /// Find pending notifications (to be sent)
34    async fn find_pending(&self) -> Result<Vec<Notification>, String>;
35
36    /// Find failed notifications (for retry)
37    async fn find_failed(&self) -> Result<Vec<Notification>, String>;
38
39    /// Find notifications by organization
40    async fn find_by_organization(
41        &self,
42        organization_id: Uuid,
43    ) -> Result<Vec<Notification>, String>;
44
45    /// Update notification
46    async fn update(&self, notification: &Notification) -> Result<Notification, String>;
47
48    /// Delete notification
49    async fn delete(&self, id: Uuid) -> Result<bool, String>;
50
51    /// Count unread notifications for user
52    async fn count_unread_by_user(&self, user_id: Uuid) -> Result<i64, String>;
53
54    /// Count notifications by user and status
55    async fn count_by_user_and_status(
56        &self,
57        user_id: Uuid,
58        status: NotificationStatus,
59    ) -> Result<i64, String>;
60
61    /// Mark all in-app notifications as read for user
62    async fn mark_all_read_by_user(&self, user_id: Uuid) -> Result<i64, String>;
63
64    /// Delete old notifications (cleanup)
65    async fn delete_older_than(&self, days: i64) -> Result<i64, String>;
66}