thunderstore_api/models/v2/
package.rs

1////////////////////////////////////////////////////////////////////////////////
2// This Source Code Form is subject to the terms of the Mozilla Public         /
3// License, v. 2.0. If a copy of the MPL was not distributed with this         /
4// file, You can obtain one at https://mozilla.org/MPL/2.0/.                   /
5////////////////////////////////////////////////////////////////////////////////
6
7#[cfg(feature = "ts-rs")]
8use ts_rs::TS;
9
10#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
11#[cfg_attr(feature = "ts-rs", derive(TS))]
12#[cfg_attr(feature = "ts-rs", ts(export))]
13pub struct Package {
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub namespace: Option<String>,
16    pub name: String,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub full_name: Option<String>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub owner: Option<String>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub package_url: Option<String>,
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub date_created: Option<String>,
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub date_updated: Option<String>,
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub rating_score: Option<String>,
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub is_pinned: Option<bool>,
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub is_deprecated: Option<bool>,
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub total_downloads: Option<String>,
35    pub latest: Version,
36    pub community_listings: Vec<Listing>,
37}
38
39impl Package {
40    #[must_use]
41    pub fn new(name: String, latest: Version, community_listings: Vec<Listing>) -> Package {
42        Package {
43            namespace: None,
44            name,
45            full_name: None,
46            owner: None,
47            package_url: None,
48            date_created: None,
49            date_updated: None,
50            rating_score: None,
51            is_pinned: None,
52            is_deprecated: None,
53            total_downloads: None,
54            latest,
55            community_listings,
56        }
57    }
58}
59
60#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
61#[cfg_attr(feature = "ts-rs", derive(TS))]
62#[cfg_attr(feature = "ts-rs", ts(export))]
63pub struct Card {
64    pub categories: Vec<Category>,
65    pub community_identifier: String,
66    pub community_name: String,
67    pub description: String,
68    pub download_count: u32,
69    pub image_src: Option<String>,
70    pub is_deprecated: bool,
71    pub is_nsfw: bool,
72    pub is_pinned: bool,
73    pub last_updated: String,
74    pub namespace: String,
75    pub package_name: String,
76    pub rating_score: u32,
77    pub team_name: String,
78}
79
80impl Card {
81    #[must_use]
82    pub fn new(
83        categories: Vec<Category>,
84        community_identifier: String,
85        community_name: String,
86        description: String,
87        download_count: u32,
88        image_src: Option<String>,
89        is_deprecated: bool,
90        is_nsfw: bool,
91        is_pinned: bool,
92        last_updated: String,
93        namespace: String,
94        package_name: String,
95        rating_score: u32,
96        team_name: String,
97    ) -> Card {
98        Card {
99            categories,
100            community_identifier,
101            community_name,
102            description,
103            download_count,
104            image_src,
105            is_deprecated,
106            is_nsfw,
107            is_pinned,
108            last_updated,
109            namespace,
110            package_name,
111            rating_score,
112            team_name,
113        }
114    }
115}
116
117#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
118#[cfg_attr(feature = "ts-rs", derive(TS))]
119#[cfg_attr(feature = "ts-rs", ts(export))]
120pub struct Category {
121    pub name: String,
122    pub slug: String,
123}
124
125impl Category {
126    #[must_use]
127    pub fn new(name: String, slug: String) -> Category {
128        Category { name, slug }
129    }
130}
131
132#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
133#[cfg_attr(feature = "ts-rs", derive(TS))]
134#[cfg_attr(feature = "ts-rs", ts(export))]
135pub struct Dependency {
136    pub community_identifier: Option<String>,
137    pub community_name: Option<String>,
138    pub description: String,
139    pub image_src: Option<String>,
140    pub namespace: String,
141    pub package_name: String,
142    pub version_number: String,
143}
144
145impl Dependency {
146    #[must_use]
147    pub fn new(
148        community_identifier: Option<String>,
149        community_name: Option<String>,
150        description: String,
151        image_src: Option<String>,
152        namespace: String,
153        package_name: String,
154        version_number: String,
155    ) -> Dependency {
156        Dependency {
157            community_identifier,
158            community_name,
159            description,
160            image_src,
161            namespace,
162            package_name,
163            version_number,
164        }
165    }
166}
167
168#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
169#[cfg_attr(feature = "ts-rs", derive(TS))]
170#[cfg_attr(feature = "ts-rs", ts(export))]
171pub struct Version {
172    #[serde(skip_serializing_if = "Option::is_none")]
173    pub namespace: Option<String>,
174    pub name: String,
175    pub version_number: String,
176    #[serde(skip_serializing_if = "Option::is_none")]
177    pub full_name: Option<String>,
178    pub description: String,
179    #[serde(skip_serializing_if = "Option::is_none")]
180    pub icon: Option<String>,
181    #[serde(skip_serializing_if = "Option::is_none")]
182    pub dependencies: Option<String>,
183    #[serde(skip_serializing_if = "Option::is_none")]
184    pub download_url: Option<String>,
185    #[serde(skip_serializing_if = "Option::is_none")]
186    pub downloads: Option<u32>,
187    #[serde(skip_serializing_if = "Option::is_none")]
188    pub date_created: Option<String>,
189    pub website_url: String,
190    #[serde(skip_serializing_if = "Option::is_none")]
191    pub is_active: Option<bool>,
192}
193
194impl Version {
195    #[must_use]
196    pub fn new(
197        name: String,
198        version_number: String,
199        description: String,
200        website_url: String,
201    ) -> Version {
202        Version {
203            namespace: None,
204            name,
205            version_number,
206            full_name: None,
207            description,
208            icon: None,
209            dependencies: None,
210            download_url: None,
211            downloads: None,
212            date_created: None,
213            website_url,
214            is_active: None,
215        }
216    }
217}
218
219#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
220#[cfg_attr(feature = "ts-rs", derive(TS))]
221#[cfg_attr(feature = "ts-rs", ts(export))]
222pub struct Listing {
223    #[serde(rename = "has_nsfw_content", skip_serializing_if = "Option::is_none")]
224    pub has_nsfw_content: Option<bool>,
225    #[serde(rename = "categories", skip_serializing_if = "Option::is_none")]
226    pub categories: Option<String>,
227    #[serde(rename = "community", skip_serializing_if = "Option::is_none")]
228    pub community: Option<String>,
229    #[serde(rename = "review_status", skip_serializing_if = "Option::is_none")]
230    pub review_status: Option<ReviewStatus>,
231}
232
233impl Listing {
234    #[must_use]
235    pub fn new() -> Listing {
236        Listing {
237            has_nsfw_content: None,
238            categories: None,
239            community: None,
240            review_status: None,
241        }
242    }
243}
244
245///
246#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
247#[cfg_attr(feature = "ts-rs", derive(TS))]
248#[cfg_attr(feature = "ts-rs", ts(export))]
249pub enum ReviewStatus {
250    #[serde(rename = "unreviewed")]
251    Unreviewed,
252    #[serde(rename = "approved")]
253    Approved,
254    #[serde(rename = "rejected")]
255    Rejected,
256}
257
258impl Default for ReviewStatus {
259    fn default() -> ReviewStatus {
260        Self::Unreviewed
261    }
262}
263
264#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
265#[cfg_attr(feature = "ts-rs", derive(TS))]
266#[cfg_attr(feature = "ts-rs", ts(export))]
267pub struct DetailView {
268    pub bg_image_src: Option<String>,
269    pub categories: Vec<Category>,
270    pub community_identifier: String,
271    pub community_name: String,
272    pub dependant_count: u32,
273    pub dependencies: Vec<Dependency>,
274    pub dependency_string: String,
275    pub description: String,
276    pub download_count: u32,
277    pub download_url: String,
278    pub image_src: Option<String>,
279    pub install_url: String,
280    pub last_updated: String,
281    pub markdown: String,
282    pub namespace: String,
283    pub package_name: String,
284    pub rating_score: u32,
285    pub team_name: String,
286    pub versions: Vec<Version>,
287    pub website: String,
288}
289
290impl DetailView {
291    #[must_use]
292    pub fn new(
293        bg_image_src: Option<String>,
294        categories: Vec<Category>,
295        community_identifier: String,
296        community_name: String,
297        dependant_count: u32,
298        dependencies: Vec<Dependency>,
299        dependency_string: String,
300        description: String,
301        download_count: u32,
302        download_url: String,
303        image_src: Option<String>,
304        install_url: String,
305        last_updated: String,
306        markdown: String,
307        namespace: String,
308        package_name: String,
309        rating_score: u32,
310        team_name: String,
311        versions: Vec<Version>,
312        website: String,
313    ) -> DetailView {
314        DetailView {
315            bg_image_src,
316            categories,
317            community_identifier,
318            community_name,
319            dependant_count,
320            dependencies,
321            dependency_string,
322            description,
323            download_count,
324            download_url,
325            image_src,
326            install_url,
327            last_updated,
328            markdown,
329            namespace,
330            package_name,
331            rating_score,
332            team_name,
333            versions,
334            website,
335        }
336    }
337}
338
339#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
340#[cfg_attr(feature = "ts-rs", derive(TS))]
341#[cfg_attr(feature = "ts-rs", ts(export))]
342pub struct ListResponse {
343    #[serde(rename = "next", skip_serializing_if = "Option::is_none")]
344    pub next: Option<String>,
345    #[serde(rename = "previous", skip_serializing_if = "Option::is_none")]
346    pub previous: Option<String>,
347    #[serde(rename = "results")]
348    pub results: Vec<Package>,
349}
350
351impl ListResponse {
352    #[must_use]
353    pub fn new(results: Vec<Package>) -> ListResponse {
354        ListResponse {
355            next: None,
356            previous: None,
357            results,
358        }
359    }
360}