1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::sync::Arc;

use async_trait::async_trait;

use crate::repository;

use super::RepositoryError;

pub type RepositoryResult<T> = std::result::Result<T, RepositoryError>;

#[async_trait]
pub trait SubscriptionRepository: Send + Sync {
    async fn put_feed_subscription(
        &self,
        feed: repository::types::FeedSubscription,
    ) -> RepositoryResult<()>;

    async fn delete_feed_subscription(
        &self,
        feed: repository::types::FeedSubscription,
    ) -> RepositoryResult<()>;

    async fn fetch_subscribed_feed_urls(&self, _user_id: &str) -> RepositoryResult<Vec<String>>;
}

#[async_trait]
impl<T> SubscriptionRepository for Arc<T>
where
    T: SubscriptionRepository,
{
    async fn put_feed_subscription(
        &self,
        feed: repository::types::FeedSubscription,
    ) -> RepositoryResult<()> {
        self.put_feed_subscription(feed).await
    }

    async fn delete_feed_subscription(
        &self,
        feed: repository::types::FeedSubscription,
    ) -> RepositoryResult<()> {
        self.delete_feed_subscription(feed).await
    }

    async fn fetch_subscribed_feed_urls(&self, user_id: &str) -> RepositoryResult<Vec<String>> {
        self.fetch_subscribed_feed_urls(user_id).await
    }
}