1use super::{ContentType, Error, configuration};
22use crate::{apis::ResponseContent, models};
23use reqwest;
24use serde::{Deserialize, Serialize, de::Error as _};
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum RecipeByIdError {
30 Status401(),
31 Status404(),
32 Status500(String),
33 UnknownValue(serde_json::Value),
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum RecipeByNameError {
40 Status401(),
41 Status404(),
42 Status500(String),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum RecipesError {
50 Status401(),
51 Status500(String),
52 UnknownValue(serde_json::Value),
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum RecipesByRecipeParentIdDirectError {
59 Status401(),
60 Status404(),
61 Status500(String),
62 UnknownValue(serde_json::Value),
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum RecipesByRecipeParentIdIndirectError {
69 Status401(),
70 Status404(),
71 Status500(String),
72 UnknownValue(serde_json::Value),
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum RecipesWithoutRecipeParentError {
79 Status401(),
80 Status500(String),
81 UnknownValue(serde_json::Value),
82}
83
84pub async fn recipe_by_id(
85 configuration: &configuration::Configuration,
86 id: models::RecipeId,
87) -> Result<models::Recipe, Error<RecipeByIdError>> {
88 let p_path_id = id;
90
91 let uri_str = format!(
92 "{}/recipe/by-id/{id}",
93 configuration.base_path,
94 id = p_path_id.to_string()
95 );
96 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
97
98 if let Some(ref user_agent) = configuration.user_agent {
99 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
100 }
101
102 let req = req_builder.build()?;
103 let resp = configuration.client.execute(req).await?;
104
105 let status = resp.status();
106 let content_type = resp
107 .headers()
108 .get("content-type")
109 .and_then(|v| v.to_str().ok())
110 .unwrap_or("application/octet-stream");
111 let content_type = super::ContentType::from(content_type);
112
113 if !status.is_client_error() && !status.is_server_error() {
114 let content = resp.text().await?;
115 match content_type {
116 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
117 ContentType::Text => {
118 return Err(Error::from(serde_json::Error::custom(
119 "Received `text/plain` content type response that cannot be converted to `models::Recipe`",
120 )));
121 }
122 ContentType::Unsupported(unknown_type) => {
123 return Err(Error::from(serde_json::Error::custom(format!(
124 "Received `{unknown_type}` content type response that cannot be converted to `models::Recipe`"
125 ))));
126 }
127 }
128 } else {
129 let content = resp.text().await?;
130 let entity: Option<RecipeByIdError> = serde_json::from_str(&content).ok();
131 Err(Error::ResponseError(ResponseContent {
132 status,
133 content,
134 entity,
135 }))
136 }
137}
138
139pub async fn recipe_by_name(
140 configuration: &configuration::Configuration,
141 name: &str,
142) -> Result<models::Recipe, Error<RecipeByNameError>> {
143 let p_path_name = name;
145
146 let uri_str = format!(
147 "{}/recipe/by-name/{name}",
148 configuration.base_path,
149 name = crate::apis::urlencode(p_path_name)
150 );
151 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
152
153 if let Some(ref user_agent) = configuration.user_agent {
154 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
155 }
156
157 let req = req_builder.build()?;
158 let resp = configuration.client.execute(req).await?;
159
160 let status = resp.status();
161 let content_type = resp
162 .headers()
163 .get("content-type")
164 .and_then(|v| v.to_str().ok())
165 .unwrap_or("application/octet-stream");
166 let content_type = super::ContentType::from(content_type);
167
168 if !status.is_client_error() && !status.is_server_error() {
169 let content = resp.text().await?;
170 match content_type {
171 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
172 ContentType::Text => {
173 return Err(Error::from(serde_json::Error::custom(
174 "Received `text/plain` content type response that cannot be converted to `models::Recipe`",
175 )));
176 }
177 ContentType::Unsupported(unknown_type) => {
178 return Err(Error::from(serde_json::Error::custom(format!(
179 "Received `{unknown_type}` content type response that cannot be converted to `models::Recipe`"
180 ))));
181 }
182 }
183 } else {
184 let content = resp.text().await?;
185 let entity: Option<RecipeByNameError> = serde_json::from_str(&content).ok();
186 Err(Error::ResponseError(ResponseContent {
187 status,
188 content,
189 entity,
190 }))
191 }
192}
193
194pub async fn recipes(
195 configuration: &configuration::Configuration,
196) -> Result<Vec<models::Recipe>, Error<RecipesError>> {
197 let uri_str = format!("{}/recipe/all", configuration.base_path);
198 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
199
200 if let Some(ref user_agent) = configuration.user_agent {
201 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
202 }
203
204 let req = req_builder.build()?;
205 let resp = configuration.client.execute(req).await?;
206
207 let status = resp.status();
208 let content_type = resp
209 .headers()
210 .get("content-type")
211 .and_then(|v| v.to_str().ok())
212 .unwrap_or("application/octet-stream");
213 let content_type = super::ContentType::from(content_type);
214
215 if !status.is_client_error() && !status.is_server_error() {
216 let content = resp.text().await?;
217 match content_type {
218 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
219 ContentType::Text => {
220 return Err(Error::from(serde_json::Error::custom(
221 "Received `text/plain` content type response that cannot be converted to `Vec<models::Recipe>`",
222 )));
223 }
224 ContentType::Unsupported(unknown_type) => {
225 return Err(Error::from(serde_json::Error::custom(format!(
226 "Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Recipe>`"
227 ))));
228 }
229 }
230 } else {
231 let content = resp.text().await?;
232 let entity: Option<RecipesError> = serde_json::from_str(&content).ok();
233 Err(Error::ResponseError(ResponseContent {
234 status,
235 content,
236 entity,
237 }))
238 }
239}
240
241pub async fn recipes_by_recipe_parent_id_direct(
243 configuration: &configuration::Configuration,
244 id: models::RecipeParentId,
245) -> Result<Vec<models::Recipe>, Error<RecipesByRecipeParentIdDirectError>> {
246 let p_path_id = id;
248
249 let uri_str = format!(
250 "{}/recipe/by-recipe-parent-id-direct/{id}",
251 configuration.base_path,
252 id = p_path_id.to_string()
253 );
254 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
255
256 if let Some(ref user_agent) = configuration.user_agent {
257 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
258 }
259
260 let req = req_builder.build()?;
261 let resp = configuration.client.execute(req).await?;
262
263 let status = resp.status();
264 let content_type = resp
265 .headers()
266 .get("content-type")
267 .and_then(|v| v.to_str().ok())
268 .unwrap_or("application/octet-stream");
269 let content_type = super::ContentType::from(content_type);
270
271 if !status.is_client_error() && !status.is_server_error() {
272 let content = resp.text().await?;
273 match content_type {
274 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
275 ContentType::Text => {
276 return Err(Error::from(serde_json::Error::custom(
277 "Received `text/plain` content type response that cannot be converted to `Vec<models::Recipe>`",
278 )));
279 }
280 ContentType::Unsupported(unknown_type) => {
281 return Err(Error::from(serde_json::Error::custom(format!(
282 "Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Recipe>`"
283 ))));
284 }
285 }
286 } else {
287 let content = resp.text().await?;
288 let entity: Option<RecipesByRecipeParentIdDirectError> =
289 serde_json::from_str(&content).ok();
290 Err(Error::ResponseError(ResponseContent {
291 status,
292 content,
293 entity,
294 }))
295 }
296}
297
298pub async fn recipes_by_recipe_parent_id_indirect(
300 configuration: &configuration::Configuration,
301 id: models::RecipeParentId,
302) -> Result<Vec<models::Recipe>, Error<RecipesByRecipeParentIdIndirectError>> {
303 let p_path_id = id;
305
306 let uri_str = format!(
307 "{}/recipe/by-recipe-parent-id-indirect/{id}",
308 configuration.base_path,
309 id = p_path_id.to_string()
310 );
311 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
312
313 if let Some(ref user_agent) = configuration.user_agent {
314 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
315 }
316
317 let req = req_builder.build()?;
318 let resp = configuration.client.execute(req).await?;
319
320 let status = resp.status();
321 let content_type = resp
322 .headers()
323 .get("content-type")
324 .and_then(|v| v.to_str().ok())
325 .unwrap_or("application/octet-stream");
326 let content_type = super::ContentType::from(content_type);
327
328 if !status.is_client_error() && !status.is_server_error() {
329 let content = resp.text().await?;
330 match content_type {
331 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
332 ContentType::Text => {
333 return Err(Error::from(serde_json::Error::custom(
334 "Received `text/plain` content type response that cannot be converted to `Vec<models::Recipe>`",
335 )));
336 }
337 ContentType::Unsupported(unknown_type) => {
338 return Err(Error::from(serde_json::Error::custom(format!(
339 "Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Recipe>`"
340 ))));
341 }
342 }
343 } else {
344 let content = resp.text().await?;
345 let entity: Option<RecipesByRecipeParentIdIndirectError> =
346 serde_json::from_str(&content).ok();
347 Err(Error::ResponseError(ResponseContent {
348 status,
349 content,
350 entity,
351 }))
352 }
353}
354
355pub async fn recipes_without_recipe_parent(
357 configuration: &configuration::Configuration,
358) -> Result<Vec<models::Recipe>, Error<RecipesWithoutRecipeParentError>> {
359 let uri_str = format!("{}/recipe/without-recipe-parent", configuration.base_path);
360 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
361
362 if let Some(ref user_agent) = configuration.user_agent {
363 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
364 }
365
366 let req = req_builder.build()?;
367 let resp = configuration.client.execute(req).await?;
368
369 let status = resp.status();
370 let content_type = resp
371 .headers()
372 .get("content-type")
373 .and_then(|v| v.to_str().ok())
374 .unwrap_or("application/octet-stream");
375 let content_type = super::ContentType::from(content_type);
376
377 if !status.is_client_error() && !status.is_server_error() {
378 let content = resp.text().await?;
379 match content_type {
380 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
381 ContentType::Text => {
382 return Err(Error::from(serde_json::Error::custom(
383 "Received `text/plain` content type response that cannot be converted to `Vec<models::Recipe>`",
384 )));
385 }
386 ContentType::Unsupported(unknown_type) => {
387 return Err(Error::from(serde_json::Error::custom(format!(
388 "Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Recipe>`"
389 ))));
390 }
391 }
392 } else {
393 let content = resp.text().await?;
394 let entity: Option<RecipesWithoutRecipeParentError> = serde_json::from_str(&content).ok();
395 Err(Error::ResponseError(ResponseContent {
396 status,
397 content,
398 entity,
399 }))
400 }
401}