koprogo_api/application/ports/
notification_repository.rs1use crate::domain::entities::{Notification, NotificationChannel, NotificationStatus};
2use async_trait::async_trait;
3use uuid::Uuid;
4
5#[async_trait]
6pub trait NotificationRepository: Send + Sync {
7 async fn create(&self, notification: &Notification) -> Result<Notification, String>;
9
10 async fn find_by_id(&self, id: Uuid) -> Result<Option<Notification>, String>;
12
13 async fn find_by_user(&self, user_id: Uuid) -> Result<Vec<Notification>, String>;
15
16 async fn find_by_user_and_status(
18 &self,
19 user_id: Uuid,
20 status: NotificationStatus,
21 ) -> Result<Vec<Notification>, String>;
22
23 async fn find_by_user_and_channel(
25 &self,
26 user_id: Uuid,
27 channel: NotificationChannel,
28 ) -> Result<Vec<Notification>, String>;
29
30 async fn find_unread_by_user(&self, user_id: Uuid) -> Result<Vec<Notification>, String>;
32
33 async fn find_pending(&self) -> Result<Vec<Notification>, String>;
35
36 async fn find_failed(&self) -> Result<Vec<Notification>, String>;
38
39 async fn find_by_organization(
41 &self,
42 organization_id: Uuid,
43 ) -> Result<Vec<Notification>, String>;
44
45 async fn update(&self, notification: &Notification) -> Result<Notification, String>;
47
48 async fn delete(&self, id: Uuid) -> Result<bool, String>;
50
51 async fn count_unread_by_user(&self, user_id: Uuid) -> Result<i64, String>;
53
54 async fn count_by_user_and_status(
56 &self,
57 user_id: Uuid,
58 status: NotificationStatus,
59 ) -> Result<i64, String>;
60
61 async fn mark_all_read_by_user(&self, user_id: Uuid) -> Result<i64, String>;
63
64 async fn delete_older_than(&self, days: i64) -> Result<i64, String>;
66}