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 CreateCollectionError {
22 Status400(models::ValidationErrorResponse),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteCollectionByIdError {
30 Status400(models::ValidationErrorResponse),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetCollectionByIdError {
38 Status400(models::ValidationErrorResponse),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetCollectionsError {
46 Status400(models::ValidationErrorResponse),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum UpdateCollectionByIdError {
54 Status400(models::ValidationErrorResponse),
55 UnknownValue(serde_json::Value),
56}
57
58
59pub async fn create_collection(configuration: &configuration::Configuration, collection_creation_dto: models::CollectionCreationDto) -> Result<models::CollectionDto, Error<CreateCollectionError>> {
61 let p_body_collection_creation_dto = collection_creation_dto;
63
64 let uri_str = format!("{}/api/v1/collections", configuration.base_path);
65 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
66
67 if let Some(ref user_agent) = configuration.user_agent {
68 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
69 }
70 if let Some(ref apikey) = configuration.api_key {
71 let key = apikey.key.clone();
72 let value = match apikey.prefix {
73 Some(ref prefix) => format!("{} {}", prefix, key),
74 None => key,
75 };
76 req_builder = req_builder.header("X-API-Key", value);
77 };
78 if let Some(ref auth_conf) = configuration.basic_auth {
79 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
80 };
81 req_builder = req_builder.json(&p_body_collection_creation_dto);
82
83 let req = req_builder.build()?;
84 let resp = configuration.client.execute(req).await?;
85
86 let status = resp.status();
87 let content_type = resp
88 .headers()
89 .get("content-type")
90 .and_then(|v| v.to_str().ok())
91 .unwrap_or("application/octet-stream");
92 let content_type = super::ContentType::from(content_type);
93
94 if !status.is_client_error() && !status.is_server_error() {
95 let content = resp.text().await?;
96 match content_type {
97 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
98 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CollectionDto`"))),
99 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::CollectionDto`")))),
100 }
101 } else {
102 let content = resp.text().await?;
103 let entity: Option<CreateCollectionError> = serde_json::from_str(&content).ok();
104 Err(Error::ResponseError(ResponseContent { status, content, entity }))
105 }
106}
107
108pub async fn delete_collection_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteCollectionByIdError>> {
110 let p_path_id = id;
112
113 let uri_str = format!("{}/api/v1/collections/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
114 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
115
116 if let Some(ref user_agent) = configuration.user_agent {
117 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
118 }
119 if let Some(ref apikey) = configuration.api_key {
120 let key = apikey.key.clone();
121 let value = match apikey.prefix {
122 Some(ref prefix) => format!("{} {}", prefix, key),
123 None => key,
124 };
125 req_builder = req_builder.header("X-API-Key", value);
126 };
127 if let Some(ref auth_conf) = configuration.basic_auth {
128 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
129 };
130
131 let req = req_builder.build()?;
132 let resp = configuration.client.execute(req).await?;
133
134 let status = resp.status();
135
136 if !status.is_client_error() && !status.is_server_error() {
137 Ok(())
138 } else {
139 let content = resp.text().await?;
140 let entity: Option<DeleteCollectionByIdError> = serde_json::from_str(&content).ok();
141 Err(Error::ResponseError(ResponseContent { status, content, entity }))
142 }
143}
144
145pub async fn get_collection_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::CollectionDto, Error<GetCollectionByIdError>> {
146 let p_path_id = id;
148
149 let uri_str = format!("{}/api/v1/collections/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
150 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
151
152 if let Some(ref user_agent) = configuration.user_agent {
153 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
154 }
155 if let Some(ref apikey) = configuration.api_key {
156 let key = apikey.key.clone();
157 let value = match apikey.prefix {
158 Some(ref prefix) => format!("{} {}", prefix, key),
159 None => key,
160 };
161 req_builder = req_builder.header("X-API-Key", value);
162 };
163 if let Some(ref auth_conf) = configuration.basic_auth {
164 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
165 };
166
167 let req = req_builder.build()?;
168 let resp = configuration.client.execute(req).await?;
169
170 let status = resp.status();
171 let content_type = resp
172 .headers()
173 .get("content-type")
174 .and_then(|v| v.to_str().ok())
175 .unwrap_or("application/octet-stream");
176 let content_type = super::ContentType::from(content_type);
177
178 if !status.is_client_error() && !status.is_server_error() {
179 let content = resp.text().await?;
180 match content_type {
181 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
182 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CollectionDto`"))),
183 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::CollectionDto`")))),
184 }
185 } else {
186 let content = resp.text().await?;
187 let entity: Option<GetCollectionByIdError> = serde_json::from_str(&content).ok();
188 Err(Error::ResponseError(ResponseContent { status, content, entity }))
189 }
190}
191
192pub async fn get_collections(configuration: &configuration::Configuration, search: Option<&str>, library_id: Option<Vec<String>>, unpaged: Option<bool>, page: Option<i32>, size: Option<i32>) -> Result<models::PageCollectionDto, Error<GetCollectionsError>> {
193 let p_query_search = search;
195 let p_query_library_id = library_id;
196 let p_query_unpaged = unpaged;
197 let p_query_page = page;
198 let p_query_size = size;
199
200 let uri_str = format!("{}/api/v1/collections", configuration.base_path);
201 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
202
203 if let Some(ref param_value) = p_query_search {
204 req_builder = req_builder.query(&[("search", ¶m_value.to_string())]);
205 }
206 if let Some(ref param_value) = p_query_library_id {
207 req_builder = match "multi" {
208 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("library_id".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
209 _ => req_builder.query(&[("library_id", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
210 };
211 }
212 if let Some(ref param_value) = p_query_unpaged {
213 req_builder = req_builder.query(&[("unpaged", ¶m_value.to_string())]);
214 }
215 if let Some(ref param_value) = p_query_page {
216 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
217 }
218 if let Some(ref param_value) = p_query_size {
219 req_builder = req_builder.query(&[("size", ¶m_value.to_string())]);
220 }
221 if let Some(ref user_agent) = configuration.user_agent {
222 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
223 }
224 if let Some(ref apikey) = configuration.api_key {
225 let key = apikey.key.clone();
226 let value = match apikey.prefix {
227 Some(ref prefix) => format!("{} {}", prefix, key),
228 None => key,
229 };
230 req_builder = req_builder.header("X-API-Key", value);
231 };
232 if let Some(ref auth_conf) = configuration.basic_auth {
233 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
234 };
235
236 let req = req_builder.build()?;
237 let resp = configuration.client.execute(req).await?;
238
239 let status = resp.status();
240 let content_type = resp
241 .headers()
242 .get("content-type")
243 .and_then(|v| v.to_str().ok())
244 .unwrap_or("application/octet-stream");
245 let content_type = super::ContentType::from(content_type);
246
247 if !status.is_client_error() && !status.is_server_error() {
248 let content = resp.text().await?;
249 match content_type {
250 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
251 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PageCollectionDto`"))),
252 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::PageCollectionDto`")))),
253 }
254 } else {
255 let content = resp.text().await?;
256 let entity: Option<GetCollectionsError> = serde_json::from_str(&content).ok();
257 Err(Error::ResponseError(ResponseContent { status, content, entity }))
258 }
259}
260
261pub async fn update_collection_by_id(configuration: &configuration::Configuration, id: &str, collection_update_dto: models::CollectionUpdateDto) -> Result<(), Error<UpdateCollectionByIdError>> {
263 let p_path_id = id;
265 let p_body_collection_update_dto = collection_update_dto;
266
267 let uri_str = format!("{}/api/v1/collections/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
268 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
269
270 if let Some(ref user_agent) = configuration.user_agent {
271 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
272 }
273 if let Some(ref apikey) = configuration.api_key {
274 let key = apikey.key.clone();
275 let value = match apikey.prefix {
276 Some(ref prefix) => format!("{} {}", prefix, key),
277 None => key,
278 };
279 req_builder = req_builder.header("X-API-Key", value);
280 };
281 if let Some(ref auth_conf) = configuration.basic_auth {
282 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
283 };
284 req_builder = req_builder.json(&p_body_collection_update_dto);
285
286 let req = req_builder.build()?;
287 let resp = configuration.client.execute(req).await?;
288
289 let status = resp.status();
290
291 if !status.is_client_error() && !status.is_server_error() {
292 Ok(())
293 } else {
294 let content = resp.text().await?;
295 let entity: Option<UpdateCollectionByIdError> = serde_json::from_str(&content).ok();
296 Err(Error::ResponseError(ResponseContent { status, content, entity }))
297 }
298}
299