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::convert::Infallible;

use async_graphql::connection::CursorType;
use synd_feed::types;

pub enum Id {
    V1(IdV1),
}

pub enum IdV1 {
    Feed(FeedIdV1),
}

pub struct FeedIdV1(String);

impl FeedIdV1 {
    pub fn new(url: impl AsRef<str>) -> Self {
        let url = url.as_ref();
        Self(format!("v1:feed:{url}"))
    }
}

impl From<FeedIdV1> for async_graphql::ID {
    fn from(v: FeedIdV1) -> Self {
        Self(v.0)
    }
}

pub(in crate::gql) struct EntryId<'a>(types::EntryId<'a>);

impl<'a> CursorType for EntryId<'a> {
    type Error = Infallible;

    fn decode_cursor(s: &str) -> Result<Self, Self::Error> {
        let s = s.to_string();
        Ok(EntryId(s.into()))
    }

    fn encode_cursor(&self) -> String {
        self.0.to_string()
    }
}

impl<'a> From<types::EntryId<'a>> for EntryId<'a> {
    fn from(value: types::EntryId<'a>) -> Self {
        Self(value)
    }
}