1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddCollectionError {
22 Status403(models::UnauthorizedApiError),
23 DefaultResponse(models::ApiError),
24 UnknownValue(serde_json::Value),
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum DeleteCollectionError {
31 Status403(models::UnauthorizedApiError),
32 Status404(models::NotFoundApiError),
33 DefaultResponse(models::ApiError),
34 UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum EditCollectionError {
41 Status403(models::UnauthorizedApiError),
42 Status404(models::NotFoundApiError),
43 DefaultResponse(models::ApiError),
44 UnknownValue(serde_json::Value),
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum GetCollectionByIdError {
51 Status403(models::UnauthorizedApiError),
52 Status404(models::NotFoundApiError),
53 DefaultResponse(models::ApiError),
54 UnknownValue(serde_json::Value),
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum GetCollectionsError {
61 Status403(models::UnauthorizedApiError),
62 DefaultResponse(models::ApiError),
63 UnknownValue(serde_json::Value),
64}
65
66
67pub async fn add_collection(configuration: &configuration::Configuration, add_collection_request: models::AddCollectionRequest) -> Result<models::AddCollection200Response, Error<AddCollectionError>> {
68 let p_add_collection_request = add_collection_request;
70
71 let uri_str = format!("{}/collections/add", configuration.base_path);
72 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
73
74 if let Some(ref user_agent) = configuration.user_agent {
75 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
76 }
77 if let Some(ref apikey) = configuration.api_key {
78 let key = apikey.key.clone();
79 let value = match apikey.prefix {
80 Some(ref prefix) => format!("{} {}", prefix, key),
81 None => key,
82 };
83 req_builder = req_builder.header("Authorization", value);
84 };
85 req_builder = req_builder.json(&p_add_collection_request);
86
87 let req = req_builder.build()?;
88 let resp = configuration.client.execute(req).await?;
89
90 let status = resp.status();
91 let content_type = resp
92 .headers()
93 .get("content-type")
94 .and_then(|v| v.to_str().ok())
95 .unwrap_or("application/octet-stream");
96 let content_type = super::ContentType::from(content_type);
97
98 if !status.is_client_error() && !status.is_server_error() {
99 let content = resp.text().await?;
100 match content_type {
101 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
102 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AddCollection200Response`"))),
103 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AddCollection200Response`")))),
104 }
105 } else {
106 let content = resp.text().await?;
107 let entity: Option<AddCollectionError> = serde_json::from_str(&content).ok();
108 Err(Error::ResponseError(ResponseContent { status, content, entity }))
109 }
110}
111
112pub async fn delete_collection(configuration: &configuration::Configuration, collection_id: &str) -> Result<models::DeleteCollection200Response, Error<DeleteCollectionError>> {
113 let p_collection_id = collection_id;
115
116 let uri_str = format!("{}/collections/delete/{collectionId}", configuration.base_path, collectionId=p_collection_id.to_string());
117 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
118
119 if let Some(ref user_agent) = configuration.user_agent {
120 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
121 }
122 if let Some(ref apikey) = configuration.api_key {
123 let key = apikey.key.clone();
124 let value = match apikey.prefix {
125 Some(ref prefix) => format!("{} {}", prefix, key),
126 None => key,
127 };
128 req_builder = req_builder.header("Authorization", value);
129 };
130
131 let req = req_builder.build()?;
132 let resp = configuration.client.execute(req).await?;
133
134 let status = resp.status();
135 let content_type = resp
136 .headers()
137 .get("content-type")
138 .and_then(|v| v.to_str().ok())
139 .unwrap_or("application/octet-stream");
140 let content_type = super::ContentType::from(content_type);
141
142 if !status.is_client_error() && !status.is_server_error() {
143 let content = resp.text().await?;
144 match content_type {
145 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
146 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteCollection200Response`"))),
147 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeleteCollection200Response`")))),
148 }
149 } else {
150 let content = resp.text().await?;
151 let entity: Option<DeleteCollectionError> = serde_json::from_str(&content).ok();
152 Err(Error::ResponseError(ResponseContent { status, content, entity }))
153 }
154}
155
156pub async fn edit_collection(configuration: &configuration::Configuration, collection_id: &str, base_collection: models::BaseCollection) -> Result<models::AddCollection200Response, Error<EditCollectionError>> {
157 let p_collection_id = collection_id;
159 let p_base_collection = base_collection;
160
161 let uri_str = format!("{}/collections/edit/{collectionId}", configuration.base_path, collectionId=p_collection_id.to_string());
162 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
163
164 if let Some(ref user_agent) = configuration.user_agent {
165 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
166 }
167 if let Some(ref apikey) = configuration.api_key {
168 let key = apikey.key.clone();
169 let value = match apikey.prefix {
170 Some(ref prefix) => format!("{} {}", prefix, key),
171 None => key,
172 };
173 req_builder = req_builder.header("Authorization", value);
174 };
175 req_builder = req_builder.json(&p_base_collection);
176
177 let req = req_builder.build()?;
178 let resp = configuration.client.execute(req).await?;
179
180 let status = resp.status();
181 let content_type = resp
182 .headers()
183 .get("content-type")
184 .and_then(|v| v.to_str().ok())
185 .unwrap_or("application/octet-stream");
186 let content_type = super::ContentType::from(content_type);
187
188 if !status.is_client_error() && !status.is_server_error() {
189 let content = resp.text().await?;
190 match content_type {
191 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
192 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AddCollection200Response`"))),
193 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AddCollection200Response`")))),
194 }
195 } else {
196 let content = resp.text().await?;
197 let entity: Option<EditCollectionError> = serde_json::from_str(&content).ok();
198 Err(Error::ResponseError(ResponseContent { status, content, entity }))
199 }
200}
201
202pub async fn get_collection_by_id(configuration: &configuration::Configuration, collection_id: &str) -> Result<models::GetCollectionById200Response, Error<GetCollectionByIdError>> {
203 let p_collection_id = collection_id;
205
206 let uri_str = format!("{}/collections/view/{collectionId}", configuration.base_path, collectionId=p_collection_id.to_string());
207 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
208
209 if let Some(ref user_agent) = configuration.user_agent {
210 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
211 }
212 if let Some(ref apikey) = configuration.api_key {
213 let key = apikey.key.clone();
214 let value = match apikey.prefix {
215 Some(ref prefix) => format!("{} {}", prefix, key),
216 None => key,
217 };
218 req_builder = req_builder.header("Authorization", value);
219 };
220
221 let req = req_builder.build()?;
222 let resp = configuration.client.execute(req).await?;
223
224 let status = resp.status();
225 let content_type = resp
226 .headers()
227 .get("content-type")
228 .and_then(|v| v.to_str().ok())
229 .unwrap_or("application/octet-stream");
230 let content_type = super::ContentType::from(content_type);
231
232 if !status.is_client_error() && !status.is_server_error() {
233 let content = resp.text().await?;
234 match content_type {
235 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
236 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetCollectionById200Response`"))),
237 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetCollectionById200Response`")))),
238 }
239 } else {
240 let content = resp.text().await?;
241 let entity: Option<GetCollectionByIdError> = serde_json::from_str(&content).ok();
242 Err(Error::ResponseError(ResponseContent { status, content, entity }))
243 }
244}
245
246pub async fn get_collections(configuration: &configuration::Configuration, filter: &str, get_collections_request: Option<models::GetCollectionsRequest>) -> Result<Vec<models::GetCollections200ResponseInner>, Error<GetCollectionsError>> {
247 let p_filter = filter;
249 let p_get_collections_request = get_collections_request;
250
251 let uri_str = format!("{}/collections/index/{filter}", configuration.base_path, filter=crate::apis::urlencode(p_filter));
252 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
253
254 if let Some(ref user_agent) = configuration.user_agent {
255 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
256 }
257 if let Some(ref apikey) = configuration.api_key {
258 let key = apikey.key.clone();
259 let value = match apikey.prefix {
260 Some(ref prefix) => format!("{} {}", prefix, key),
261 None => key,
262 };
263 req_builder = req_builder.header("Authorization", value);
264 };
265 req_builder = req_builder.json(&p_get_collections_request);
266
267 let req = req_builder.build()?;
268 let resp = configuration.client.execute(req).await?;
269
270 let status = resp.status();
271 let content_type = resp
272 .headers()
273 .get("content-type")
274 .and_then(|v| v.to_str().ok())
275 .unwrap_or("application/octet-stream");
276 let content_type = super::ContentType::from(content_type);
277
278 if !status.is_client_error() && !status.is_server_error() {
279 let content = resp.text().await?;
280 match content_type {
281 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
282 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::GetCollections200ResponseInner>`"))),
283 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::GetCollections200ResponseInner>`")))),
284 }
285 } else {
286 let content = resp.text().await?;
287 let entity: Option<GetCollectionsError> = serde_json::from_str(&content).ok();
288 Err(Error::ResponseError(ResponseContent { status, content, entity }))
289 }
290}
291