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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
pub mod site_kit;
use crate::pages::PageId;
pub trait SiteRepository {
fn create(&mut self, site: Box<dyn Site>) -> Box<dyn SiteId>;
fn read(&self, read_by: SiteReadOption) -> (&Box<dyn Site>, Box<dyn SiteId>);
fn delete(&self, site_id: Box<dyn Site>) -> bool;
}
pub trait CreatedSite {
fn site(&self) -> dyn Site;
fn site_id(&self) -> Box<dyn SiteId>;
}
pub trait SiteIdBuilder {
fn build(&self, id: u8) -> Box<dyn SiteId>;
}
pub struct SiteIdBuilderImpl;
impl SiteIdBuilderImpl {
pub fn new() -> Box<dyn SiteIdBuilder> {
let result: Box<dyn SiteIdBuilder> = Box::new(SiteIdBuilderImpl {});
result
}
}
impl SiteIdBuilder for SiteIdBuilderImpl {
fn build(&self, id: u8) -> Box<dyn SiteId> {
let result = SiteIdImpl { value: id };
let b: Box<dyn SiteId> = Box::new(result);
b
}
}
pub trait Reader {
fn read(&self, site_id: Box<dyn SiteId>) -> Box<dyn Site>;
}
pub struct SiteReader<'a> {
site_repository: &'a Box<dyn SiteRepository>,
}
impl SiteReader<'_> {
fn new(site_repository: &Box<dyn SiteRepository>) -> Box<dyn Reader + '_> {
Box::new(SiteReader { site_repository })
}
}
impl Reader for SiteReader<'_> {
fn read(&self, site_id: Box<dyn SiteId>) -> Box<dyn Site> {
todo!()
}
}
pub trait SiteBuilder {
fn build(&self) -> Box<dyn Site>;
}
pub struct SiteBuilderImpl;
impl SiteBuilderImpl {
fn new() -> Box<dyn SiteBuilder> {
let result: Box<dyn SiteBuilder> = Box::new(SiteBuilderImpl {});
result
}
}
impl SiteBuilder for SiteBuilderImpl {
fn build(&self) -> Box<dyn Site> {
let site = SiteImpl { domain: "domain.com".to_string(), name: "".to_string() };
let result: Box<dyn Site> = Box::new(site);
result
}
}
pub enum SiteReadOption {
SiteId(Box<dyn SiteId>),
Domain(String),
}
pub trait Site {
fn domain(&self) -> String;
}
struct SiteImpl {
domain: String,
name: String,
}
impl Site for SiteImpl {
fn domain(&self) -> String {
self.domain.clone()
}
}
pub trait SiteId {
fn value(&self) -> u8;
}
struct SiteIdImpl {
value: u8,
}
impl SiteId for SiteIdImpl {
fn value(&self) -> u8 {
self.value
}
}
pub struct SitePages {
pages: Vec<PageId>,
}