1use {
4 crate::{
5 models::{
6 blog::Post,
7 core::{Comment, Part, User},
8 story::{Chapter, Character, Origin, Pairing, Series, Story, Tag, Warning},
9 wiki::{Category, Page},
10 Existing, Id, New,
11 },
12 uri::Uri,
13 },
14 std::error::Error,
15};
16
17#[cfg(feature = "with-backend")]
19#[async_trait::async_trait]
20pub trait BackendFactory {
21 type Error: Error;
22 type Backend: Backend<Self::Error>;
23
24 async fn create(&self, config: Uri) -> Result<Self::Backend, Self::Error>;
26}
27
28#[cfg(feature = "with-backend")]
52#[rustfmt::skip]
53#[async_trait::async_trait]
54pub trait Backend<Err>:
55 BackendEntry<User, Err>
57 + BackendEntry<Comment, Err>
58 + BackendEntry<Part, Err>
59 + BackendEntry<Post, Err>
61 + BackendEntry<Chapter, Err>
63 + BackendEntry<Origin, Err>
64 + BackendEntry<Warning, Err>
65 + BackendEntry<Pairing, Err>
66 + BackendEntry<Character, Err>
67 + BackendEntry<Tag, Err>
68 + BackendEntry<Story, Err>
69 + BackendEntry<Series, Err>
70 + BackendEntry<Category, Err>
72 + BackendEntry<Page, Err>
73where
74 Err: Error,
75{
76 async fn migrate(&self) -> Result<(), Err>;
78}
79
80#[cfg(feature = "with-backend")]
82#[async_trait::async_trait]
83pub trait BackendEntry<Entry, Error> {
84 async fn get(&self, id: Id) -> Result<Existing<Entry>, Error>;
86 async fn all(&self, cursor: Id, limit: usize) -> Result<Vec<Existing<Entry>>, Error>;
88
89 async fn create(&self, data: New<Entry>) -> Result<Id, Error>;
91 async fn update(&self, data: Existing<Entry>) -> Result<(), Error>;
93 async fn remove(&self, id: Id) -> Result<(), Error>;
95}