thunderstore_api/models/v2/
community.rs1use crate::models::v2::package;
8#[cfg(feature = "ts-rs")]
9use ts_rs::TS;
10
11#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
12#[cfg_attr(feature = "ts-rs", derive(TS))]
13#[cfg_attr(feature = "ts-rs", ts(export))]
14pub struct Community {
15 pub identifier: String,
16 pub name: String,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub discord_url: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub wiki_url: Option<String>,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub require_package_listing_approval: Option<bool>,
23}
24
25impl Community {
26 #[must_use]
27 pub fn new(identifier: String, name: String) -> Community {
28 Community {
29 identifier,
30 name,
31 discord_url: None,
32 wiki_url: None,
33 require_package_listing_approval: None,
34 }
35 }
36}
37
38#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
39#[cfg_attr(feature = "ts-rs", derive(TS))]
40#[cfg_attr(feature = "ts-rs", ts(export))]
41pub struct PackageList {
42 pub bg_image_src: Option<String>,
43 pub categories: Vec<package::Category>,
44 pub community_name: String,
45 pub has_more_pages: bool,
46 pub packages: Vec<package::Card>,
47}
48
49impl PackageList {
50 #[must_use]
51 pub fn new(
52 bg_image_src: Option<String>,
53 categories: Vec<package::Category>,
54 community_name: String,
55 has_more_pages: bool,
56 packages: Vec<package::Card>,
57 ) -> PackageList {
58 PackageList {
59 bg_image_src,
60 categories,
61 community_name,
62 has_more_pages,
63 packages,
64 }
65 }
66}
67
68#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
69#[cfg_attr(feature = "ts-rs", derive(TS))]
70#[cfg_attr(feature = "ts-rs", ts(export))]
71pub struct Card {
72 pub bg_image_src: Option<String>,
73 pub download_count: u32,
74 pub identifier: String,
75 pub name: String,
76 pub package_count: u32,
77}
78
79impl Card {
80 #[must_use]
81 pub fn new(
82 bg_image_src: Option<String>,
83 download_count: u32,
84 identifier: String,
85 name: String,
86 package_count: u32,
87 ) -> Card {
88 Card {
89 bg_image_src,
90 download_count,
91 identifier,
92 name,
93 package_count,
94 }
95 }
96}
97
98#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
99#[cfg_attr(feature = "ts-rs", derive(TS))]
100#[cfg_attr(feature = "ts-rs", ts(export))]
101pub struct ListResponse {
102 #[serde(skip_serializing_if = "Option::is_none")]
103 pub next: Option<String>,
104 #[serde(skip_serializing_if = "Option::is_none")]
105 pub previous: Option<String>,
106 pub results: Vec<Community>,
107}
108
109impl ListResponse {
110 #[must_use]
111 pub fn new(results: Vec<Community>) -> ListResponse {
112 ListResponse {
113 next: None,
114 previous: None,
115 results,
116 }
117 }
118}
119
120#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
121#[cfg_attr(feature = "ts-rs", derive(TS))]
122#[cfg_attr(feature = "ts-rs", ts(export))]
123pub struct CategoryListResponse {
124 #[serde(skip_serializing_if = "Option::is_none")]
125 pub next: Option<String>,
126 #[serde(skip_serializing_if = "Option::is_none")]
127 pub previous: Option<String>,
128 pub results: Vec<package::Category>,
129}
130
131impl CategoryListResponse {
132 #[must_use]
133 pub fn new(results: Vec<package::Category>) -> CategoryListResponse {
134 CategoryListResponse {
135 next: None,
136 previous: None,
137 results,
138 }
139 }
140}