hypercall_db/traits/notifications.rs
1//! Notification feed persistence traits (async).
2//!
3//! Used by `NotificationService` for the persisted notification feed.
4//! Redis caching of the has-unread bit stays in the service layer.
5
6use anyhow::Result;
7use async_trait::async_trait;
8use chrono::{DateTime, Utc};
9
10use crate::{NewNotificationInput, NotificationRecord};
11
12/// Read-only notification queries.
13#[async_trait]
14pub trait NotificationReader: Send + Sync {
15 /// List notifications for a wallet, ordered by id descending.
16 /// If `before_id` is set, only return notifications with id < before_id.
17 async fn list_notifications(
18 &self,
19 wallet: &str,
20 before_id: Option<i64>,
21 limit: i64,
22 ) -> Result<Vec<NotificationRecord>>;
23
24 /// Count unread notifications for a wallet.
25 async fn count_unread_notifications(&self, wallet: &str) -> Result<i64>;
26}
27
28/// Write operations for the notification feed.
29#[async_trait]
30pub trait NotificationWriter: NotificationReader {
31 /// Insert a new notification, returning the inserted row.
32 async fn insert_notification(&self, input: NewNotificationInput) -> Result<NotificationRecord>;
33
34 /// Mark specific notification ids as read for a wallet.
35 /// Returns the number of rows updated.
36 async fn mark_notifications_read(
37 &self,
38 wallet: &str,
39 ids: &[i64],
40 now: DateTime<Utc>,
41 ) -> Result<usize>;
42
43 /// Mark all unread notifications as read for a wallet.
44 /// Returns the number of rows updated.
45 async fn mark_all_notifications_read(&self, wallet: &str, now: DateTime<Utc>) -> Result<usize>;
46}