veruna_kernel/sites/
mod.rs

1pub mod site_kit;
2
3use crate::pages::PageId;
4use async_trait::async_trait;
5
6#[async_trait(?Send)]
7pub trait SiteRepository {
8    async fn create(&mut self, site: Box<dyn Site>) -> Box<dyn SiteId>;
9    fn read(&self, read_by: SiteReadOption) -> (&Box<dyn Site>, Box<dyn SiteId>);
10    fn delete(&self, site_id: Box<dyn Site>) -> bool;
11}
12
13pub trait CreatedSite {
14    fn site(&self) -> dyn Site;
15    fn site_id(&self) -> Box<dyn SiteId>;
16}
17
18pub trait SiteIdBuilder {
19    fn build(&self, id: u8) -> Box<dyn SiteId>;
20}
21
22pub struct SiteIdBuilderImpl;
23
24impl SiteIdBuilderImpl {
25    pub fn new() -> Box<dyn SiteIdBuilder> {
26        let result: Box<dyn SiteIdBuilder> = Box::new(SiteIdBuilderImpl {});
27        result
28    }
29}
30
31impl SiteIdBuilder for SiteIdBuilderImpl {
32    fn build(&self, id: u8) -> Box<dyn SiteId> {
33        let result = SiteIdImpl { value: id };
34        let b: Box<dyn SiteId> = Box::new(result);
35        b
36    }
37}
38
39
40pub trait Reader {
41    fn read(&self, site_id: Box<dyn SiteId>) -> Box<dyn Site>;
42}
43
44pub struct SiteReader<'a> {
45    site_repository: &'a Box<dyn SiteRepository>,
46}
47
48impl SiteReader<'_> {
49    fn new(site_repository: &Box<dyn SiteRepository>) -> Box<dyn Reader + '_> {
50        Box::new(SiteReader { site_repository })
51    }
52}
53
54impl Reader for SiteReader<'_> {
55    fn read(&self, site_id: Box<dyn SiteId>) -> Box<dyn Site> {
56        todo!()
57    }
58}
59
60
61pub trait SiteBuilder {
62    fn build(&self) -> Box<dyn Site>;
63}
64
65pub struct SiteBuilderImpl;
66
67impl SiteBuilderImpl {
68    fn new() -> Box<dyn SiteBuilder> {
69        let result: Box<dyn SiteBuilder> = Box::new(SiteBuilderImpl {});
70        result
71    }
72}
73
74impl SiteBuilder for SiteBuilderImpl {
75    fn build(&self) -> Box<dyn Site> {
76        let site = SiteImpl { domain: "domain.com".to_string(), name: "".to_string() };
77        let result: Box<dyn Site> = Box::new(site);
78        result
79    }
80}
81
82pub enum SiteReadOption {
83    SiteId(Box<dyn SiteId>),
84    Domain(String),
85}
86
87pub trait Site {
88    fn domain(&self) -> String;
89}
90
91struct SiteImpl {
92    domain: String,
93    name: String,
94}
95
96impl Site for SiteImpl {
97    fn domain(&self) -> String {
98        self.domain.clone()
99    }
100}
101
102pub trait SiteId {
103    fn value(&self) -> u8;
104}
105
106struct SiteIdImpl {
107    value: u8,
108}
109
110impl SiteId for SiteIdImpl {
111    fn value(&self) -> u8 {
112        self.value
113    }
114}
115
116pub struct SitePages {
117    pages: Vec<PageId>,
118}