koprogo_api/application/ports/
notification_preference_repository.rs

1use crate::domain::entities::{NotificationChannel, NotificationPreference, NotificationType};
2use async_trait::async_trait;
3use uuid::Uuid;
4
5#[async_trait]
6pub trait NotificationPreferenceRepository: Send + Sync {
7    /// Create a new notification preference
8    async fn create(
9        &self,
10        preference: &NotificationPreference,
11    ) -> Result<NotificationPreference, String>;
12
13    /// Find preference by ID
14    async fn find_by_id(&self, id: Uuid) -> Result<Option<NotificationPreference>, String>;
15
16    /// Find preference by user and notification type
17    async fn find_by_user_and_type(
18        &self,
19        user_id: Uuid,
20        notification_type: NotificationType,
21    ) -> Result<Option<NotificationPreference>, String>;
22
23    /// Find all preferences for a user
24    async fn find_by_user(&self, user_id: Uuid) -> Result<Vec<NotificationPreference>, String>;
25
26    /// Update preference
27    async fn update(
28        &self,
29        preference: &NotificationPreference,
30    ) -> Result<NotificationPreference, String>;
31
32    /// Delete preference
33    async fn delete(&self, id: Uuid) -> Result<bool, String>;
34
35    /// Check if user has enabled a specific channel for a notification type
36    async fn is_channel_enabled(
37        &self,
38        user_id: Uuid,
39        notification_type: NotificationType,
40        channel: NotificationChannel,
41    ) -> Result<bool, String>;
42
43    /// Create default preferences for a new user
44    async fn create_defaults_for_user(
45        &self,
46        user_id: Uuid,
47    ) -> Result<Vec<NotificationPreference>, String>;
48}