systemprompt_content/models/builders/
content.rs1use chrono::{DateTime, Utc};
2use systemprompt_identifiers::{CategoryId, ContentId, SourceId};
3
4#[derive(Debug, Clone)]
5pub enum CategoryIdUpdate {
6 Unchanged,
7 Clear,
8 Set(CategoryId),
9}
10
11impl From<Option<Option<CategoryId>>> for CategoryIdUpdate {
12 fn from(value: Option<Option<CategoryId>>) -> Self {
13 match value {
14 None => Self::Unchanged,
15 Some(None) => Self::Clear,
16 Some(Some(id)) => Self::Set(id),
17 }
18 }
19}
20
21#[derive(Debug, Clone)]
22pub struct CreateContentParams {
23 pub slug: String,
24 pub title: String,
25 pub description: String,
26 pub body: String,
27 pub author: String,
28 pub published_at: DateTime<Utc>,
29 pub keywords: String,
30 pub kind: String,
31 pub image: Option<String>,
32 pub category_id: Option<CategoryId>,
33 pub source_id: SourceId,
34 pub version_hash: String,
35 pub links: serde_json::Value,
36 pub public: bool,
37}
38
39impl CreateContentParams {
40 pub fn new(
41 slug: String,
42 title: String,
43 description: String,
44 body: String,
45 source_id: SourceId,
46 ) -> Self {
47 Self {
48 slug,
49 title,
50 description,
51 body,
52 author: String::new(),
53 published_at: Utc::now(),
54 keywords: String::new(),
55 kind: "article".into(),
56 image: None,
57 category_id: None,
58 source_id,
59 version_hash: String::new(),
60 links: serde_json::Value::Array(vec![]),
61 public: true,
62 }
63 }
64
65 pub fn with_author(mut self, author: String) -> Self {
66 self.author = author;
67 self
68 }
69
70 pub const fn with_published_at(mut self, published_at: DateTime<Utc>) -> Self {
71 self.published_at = published_at;
72 self
73 }
74
75 pub fn with_keywords(mut self, keywords: String) -> Self {
76 self.keywords = keywords;
77 self
78 }
79
80 pub fn with_kind(mut self, kind: String) -> Self {
81 self.kind = kind;
82 self
83 }
84
85 pub fn with_image(mut self, image: Option<String>) -> Self {
86 self.image = image;
87 self
88 }
89
90 pub fn with_category_id(mut self, category_id: Option<CategoryId>) -> Self {
91 self.category_id = category_id;
92 self
93 }
94
95 pub fn with_version_hash(mut self, version_hash: String) -> Self {
96 self.version_hash = version_hash;
97 self
98 }
99
100 pub fn with_links(mut self, links: serde_json::Value) -> Self {
101 self.links = links;
102 self
103 }
104
105 pub const fn with_public(mut self, public: bool) -> Self {
106 self.public = public;
107 self
108 }
109}
110
111#[derive(Debug, Clone)]
112pub struct UpdateContentParams {
113 pub id: ContentId,
114 pub title: String,
115 pub description: String,
116 pub body: String,
117 pub keywords: String,
118 pub image: Option<String>,
119 pub version_hash: String,
120 pub category_id: CategoryIdUpdate,
121 pub public: Option<bool>,
122 pub kind: Option<String>,
123 pub author: Option<String>,
124 pub published_at: Option<DateTime<Utc>>,
125 pub links: Option<serde_json::Value>,
126}
127
128impl UpdateContentParams {
129 pub const fn new(id: ContentId, title: String, description: String, body: String) -> Self {
130 Self {
131 id,
132 title,
133 description,
134 body,
135 keywords: String::new(),
136 image: None,
137 version_hash: String::new(),
138 category_id: CategoryIdUpdate::Unchanged,
139 public: None,
140 kind: None,
141 author: None,
142 published_at: None,
143 links: None,
144 }
145 }
146
147 pub fn with_keywords(mut self, keywords: String) -> Self {
148 self.keywords = keywords;
149 self
150 }
151
152 pub fn with_image(mut self, image: Option<String>) -> Self {
153 self.image = image;
154 self
155 }
156
157 pub fn with_version_hash(mut self, version_hash: String) -> Self {
158 self.version_hash = version_hash;
159 self
160 }
161
162 pub fn with_category_id(mut self, category_id: impl Into<CategoryIdUpdate>) -> Self {
163 self.category_id = category_id.into();
164 self
165 }
166
167 pub const fn with_public(mut self, public: Option<bool>) -> Self {
168 self.public = public;
169 self
170 }
171
172 pub fn with_kind(mut self, kind: Option<String>) -> Self {
173 self.kind = kind;
174 self
175 }
176
177 pub fn with_author(mut self, author: Option<String>) -> Self {
178 self.author = author;
179 self
180 }
181
182 pub const fn with_published_at(mut self, published_at: Option<DateTime<Utc>>) -> Self {
183 self.published_at = published_at;
184 self
185 }
186
187 pub fn with_links(mut self, links: Option<serde_json::Value>) -> Self {
188 self.links = links;
189 self
190 }
191}