artcoded_api/apis/
todo_controller_api.rs1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum DeleteError {
20 UnknownValue(serde_json::Value),
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum FindAllError {
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum SaveOrUpdateError {
34 UnknownValue(serde_json::Value),
35}
36
37pub async fn delete(
38 configuration: &configuration::Configuration,
39 id: &str,
40) -> Result<(), Error<DeleteError>> {
41 let p_query_id = id;
43
44 let uri_str = format!("{}/api/todo", configuration.base_path);
45 let mut req_builder = configuration
46 .client
47 .request(reqwest::Method::DELETE, &uri_str);
48
49 req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
50 if let Some(ref user_agent) = configuration.user_agent {
51 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
52 }
53 if let Some(ref token) = configuration.bearer_access_token {
54 req_builder = req_builder.bearer_auth(token.to_owned());
55 };
56
57 let req = req_builder.build()?;
58 let resp = configuration.client.execute(req).await?;
59
60 let status = resp.status();
61
62 if !status.is_client_error() && !status.is_server_error() {
63 Ok(())
64 } else {
65 let content = resp.text().await?;
66 let entity: Option<DeleteError> = serde_json::from_str(&content).ok();
67 Err(Error::ResponseError(ResponseContent {
68 status,
69 content,
70 entity,
71 }))
72 }
73}
74
75pub async fn find_all(
76 configuration: &configuration::Configuration,
77) -> Result<Vec<models::Todo>, Error<FindAllError>> {
78 let uri_str = format!("{}/api/todo", configuration.base_path);
79 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
80
81 if let Some(ref user_agent) = configuration.user_agent {
82 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
83 }
84 if let Some(ref token) = configuration.bearer_access_token {
85 req_builder = req_builder.bearer_auth(token.to_owned());
86 };
87
88 let req = req_builder.build()?;
89 let resp = configuration.client.execute(req).await?;
90
91 let status = resp.status();
92 let content_type = resp
93 .headers()
94 .get("content-type")
95 .and_then(|v| v.to_str().ok())
96 .unwrap_or("application/octet-stream");
97 let content_type = super::ContentType::from(content_type);
98
99 if !status.is_client_error() && !status.is_server_error() {
100 let content = resp.text().await?;
101 match content_type {
102 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
103 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Todo>`"))),
104 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Todo>`")))),
105 }
106 } else {
107 let content = resp.text().await?;
108 let entity: Option<FindAllError> = serde_json::from_str(&content).ok();
109 Err(Error::ResponseError(ResponseContent {
110 status,
111 content,
112 entity,
113 }))
114 }
115}
116
117pub async fn save_or_update(
118 configuration: &configuration::Configuration,
119 todo: models::Todo,
120) -> Result<models::Todo, Error<SaveOrUpdateError>> {
121 let p_body_todo = todo;
123
124 let uri_str = format!("{}/api/todo", configuration.base_path);
125 let mut req_builder = configuration
126 .client
127 .request(reqwest::Method::POST, &uri_str);
128
129 if let Some(ref user_agent) = configuration.user_agent {
130 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
131 }
132 if let Some(ref token) = configuration.bearer_access_token {
133 req_builder = req_builder.bearer_auth(token.to_owned());
134 };
135 req_builder = req_builder.json(&p_body_todo);
136
137 let req = req_builder.build()?;
138 let resp = configuration.client.execute(req).await?;
139
140 let status = resp.status();
141 let content_type = resp
142 .headers()
143 .get("content-type")
144 .and_then(|v| v.to_str().ok())
145 .unwrap_or("application/octet-stream");
146 let content_type = super::ContentType::from(content_type);
147
148 if !status.is_client_error() && !status.is_server_error() {
149 let content = resp.text().await?;
150 match content_type {
151 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
152 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Todo`"))),
153 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Todo`")))),
154 }
155 } else {
156 let content = resp.text().await?;
157 let entity: Option<SaveOrUpdateError> = serde_json::from_str(&content).ok();
158 Err(Error::ResponseError(ResponseContent {
159 status,
160 content,
161 entity,
162 }))
163 }
164}