Skip to main content

hypercall_db/traits/
push.rs

1//! Push subscription persistence traits (async).
2//!
3//! Used by `PushNotificationService` for managing Web Push subscriptions.
4//! In-memory caching and VAPID signing stay in the service layer.
5
6use anyhow::Result;
7use async_trait::async_trait;
8
9use crate::{PushSubscriptionRecord, UpsertPushSubscriptionInput};
10
11/// Read-only push subscription queries.
12#[async_trait]
13pub trait PushSubscriptionReader: Send + Sync {
14    /// Load all push subscriptions for a wallet.
15    async fn get_push_subscriptions(&self, wallet: &str) -> Result<Vec<PushSubscriptionRecord>>;
16
17    /// Count push subscriptions for a wallet.
18    async fn count_push_subscriptions(&self, wallet: &str) -> Result<i64>;
19
20    /// Check if a specific endpoint exists for a wallet.
21    async fn push_subscription_exists(&self, wallet: &str, endpoint: &str) -> Result<bool>;
22}
23
24/// Write operations for push subscriptions.
25#[async_trait]
26pub trait PushSubscriptionWriter: PushSubscriptionReader {
27    /// Upsert a push subscription (insert or update on conflict).
28    /// On conflict (wallet_address, endpoint), updates auth_key, p256dh_key, and preferences.
29    async fn upsert_push_subscription(
30        &self,
31        input: UpsertPushSubscriptionInput,
32    ) -> Result<PushSubscriptionRecord>;
33
34    /// Update preferences for an existing subscription.
35    /// Returns true if a row was updated.
36    async fn update_push_preferences(
37        &self,
38        wallet: &str,
39        endpoint: &str,
40        preferences: serde_json::Value,
41    ) -> Result<bool>;
42
43    /// Delete a push subscription by wallet + endpoint.
44    /// Returns true if a row was deleted.
45    async fn delete_push_subscription(&self, wallet: &str, endpoint: &str) -> Result<bool>;
46
47    /// Delete a push subscription by id.
48    async fn delete_push_subscription_by_id(&self, id: i64) -> Result<bool>;
49}