systemprompt_content/models/builders/
content.rs1use chrono::{DateTime, Utc};
2use systemprompt_identifiers::{CategoryId, ContentId, SourceId};
3
4#[derive(Debug, Clone)]
5pub struct CreateContentParams {
6 pub slug: String,
7 pub title: String,
8 pub description: String,
9 pub body: String,
10 pub author: String,
11 pub published_at: DateTime<Utc>,
12 pub keywords: String,
13 pub kind: String,
14 pub image: Option<String>,
15 pub category_id: Option<CategoryId>,
16 pub source_id: SourceId,
17 pub version_hash: String,
18 pub links: serde_json::Value,
19}
20
21impl CreateContentParams {
22 pub fn new(
23 slug: String,
24 title: String,
25 description: String,
26 body: String,
27 source_id: SourceId,
28 ) -> Self {
29 Self {
30 slug,
31 title,
32 description,
33 body,
34 author: String::new(),
35 published_at: Utc::now(),
36 keywords: String::new(),
37 kind: String::from("article"),
38 image: None,
39 category_id: None,
40 source_id,
41 version_hash: String::new(),
42 links: serde_json::Value::Array(vec![]),
43 }
44 }
45
46 pub fn with_author(mut self, author: String) -> Self {
47 self.author = author;
48 self
49 }
50
51 pub const fn with_published_at(mut self, published_at: DateTime<Utc>) -> Self {
52 self.published_at = published_at;
53 self
54 }
55
56 pub fn with_keywords(mut self, keywords: String) -> Self {
57 self.keywords = keywords;
58 self
59 }
60
61 pub fn with_kind(mut self, kind: String) -> Self {
62 self.kind = kind;
63 self
64 }
65
66 pub fn with_image(mut self, image: Option<String>) -> Self {
67 self.image = image;
68 self
69 }
70
71 pub fn with_category_id(mut self, category_id: Option<CategoryId>) -> Self {
72 self.category_id = category_id;
73 self
74 }
75
76 pub fn with_version_hash(mut self, version_hash: String) -> Self {
77 self.version_hash = version_hash;
78 self
79 }
80
81 pub fn with_links(mut self, links: serde_json::Value) -> Self {
82 self.links = links;
83 self
84 }
85}
86
87#[derive(Debug, Clone)]
88pub struct UpdateContentParams {
89 pub id: ContentId,
90 pub title: String,
91 pub description: String,
92 pub body: String,
93 pub keywords: String,
94 pub image: Option<String>,
95 pub version_hash: String,
96 #[allow(clippy::option_option)]
97 pub category_id: Option<Option<CategoryId>>,
98 pub public: Option<bool>,
99 pub kind: Option<String>,
100}
101
102impl UpdateContentParams {
103 pub const fn new(id: ContentId, title: String, description: String, body: String) -> Self {
104 Self {
105 id,
106 title,
107 description,
108 body,
109 keywords: String::new(),
110 image: None,
111 version_hash: String::new(),
112 category_id: None,
113 public: None,
114 kind: None,
115 }
116 }
117
118 pub fn with_keywords(mut self, keywords: String) -> Self {
119 self.keywords = keywords;
120 self
121 }
122
123 pub fn with_image(mut self, image: Option<String>) -> Self {
124 self.image = image;
125 self
126 }
127
128 pub fn with_version_hash(mut self, version_hash: String) -> Self {
129 self.version_hash = version_hash;
130 self
131 }
132
133 #[allow(clippy::option_option)]
134 pub fn with_category_id(mut self, category_id: Option<Option<CategoryId>>) -> Self {
135 self.category_id = category_id;
136 self
137 }
138
139 pub const fn with_public(mut self, public: Option<bool>) -> Self {
140 self.public = public;
141 self
142 }
143
144 pub fn with_kind(mut self, kind: Option<String>) -> Self {
145 self.kind = kind;
146 self
147 }
148}