Skip to main content

systemprompt_content/models/builders/
content.rs

1use 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    pub author: Option<String>,
101    pub published_at: Option<DateTime<Utc>>,
102    pub links: Option<serde_json::Value>,
103}
104
105impl UpdateContentParams {
106    pub const fn new(id: ContentId, title: String, description: String, body: String) -> Self {
107        Self {
108            id,
109            title,
110            description,
111            body,
112            keywords: String::new(),
113            image: None,
114            version_hash: String::new(),
115            category_id: None,
116            public: None,
117            kind: None,
118            author: None,
119            published_at: None,
120            links: None,
121        }
122    }
123
124    pub fn with_keywords(mut self, keywords: String) -> Self {
125        self.keywords = keywords;
126        self
127    }
128
129    pub fn with_image(mut self, image: Option<String>) -> Self {
130        self.image = image;
131        self
132    }
133
134    pub fn with_version_hash(mut self, version_hash: String) -> Self {
135        self.version_hash = version_hash;
136        self
137    }
138
139    #[allow(clippy::option_option)]
140    pub fn with_category_id(mut self, category_id: Option<Option<CategoryId>>) -> Self {
141        self.category_id = category_id;
142        self
143    }
144
145    pub const fn with_public(mut self, public: Option<bool>) -> Self {
146        self.public = public;
147        self
148    }
149
150    pub fn with_kind(mut self, kind: Option<String>) -> Self {
151        self.kind = kind;
152        self
153    }
154
155    pub fn with_author(mut self, author: Option<String>) -> Self {
156        self.author = author;
157        self
158    }
159
160    pub const fn with_published_at(mut self, published_at: Option<DateTime<Utc>>) -> Self {
161        self.published_at = published_at;
162        self
163    }
164
165    pub fn with_links(mut self, links: Option<serde_json::Value>) -> Self {
166        self.links = links;
167        self
168    }
169}