p7m_appointment/apis/
service_api.rs1use 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 DeleteServiceByIdError {
22 Status400(),
23 Status404(),
24 UnknownValue(serde_json::Value),
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetServiceByIdError {
31 Status404(),
32 UnknownValue(serde_json::Value),
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetServicesError {
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum PostServiceError {
46 UnknownValue(serde_json::Value),
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum PutServiceByIdError {
53 Status400(),
54 Status404(),
55 UnknownValue(serde_json::Value),
56}
57
58
59pub async fn delete_service_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteServiceByIdError>> {
60 let p_id = id;
62
63 let uri_str = format!("{}/services/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
64 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
65
66 if let Some(ref user_agent) = configuration.user_agent {
67 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
68 }
69 if let Some(ref token) = configuration.oauth_access_token {
70 req_builder = req_builder.bearer_auth(token.to_owned());
71 };
72
73 let req = req_builder.build()?;
74 let resp = configuration.client.execute(req).await?;
75
76 let status = resp.status();
77
78 if !status.is_client_error() && !status.is_server_error() {
79 Ok(())
80 } else {
81 let content = resp.text().await?;
82 let entity: Option<DeleteServiceByIdError> = serde_json::from_str(&content).ok();
83 Err(Error::ResponseError(ResponseContent { status, content, entity }))
84 }
85}
86
87pub async fn get_service_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Service, Error<GetServiceByIdError>> {
88 let p_id = id;
90
91 let uri_str = format!("{}/services/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
92 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
93
94 if let Some(ref user_agent) = configuration.user_agent {
95 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
96 }
97 if let Some(ref token) = configuration.oauth_access_token {
98 req_builder = req_builder.bearer_auth(token.to_owned());
99 };
100
101 let req = req_builder.build()?;
102 let resp = configuration.client.execute(req).await?;
103
104 let status = resp.status();
105 let content_type = resp
106 .headers()
107 .get("content-type")
108 .and_then(|v| v.to_str().ok())
109 .unwrap_or("application/octet-stream");
110 let content_type = super::ContentType::from(content_type);
111
112 if !status.is_client_error() && !status.is_server_error() {
113 let content = resp.text().await?;
114 match content_type {
115 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
116 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Service`"))),
117 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::Service`")))),
118 }
119 } else {
120 let content = resp.text().await?;
121 let entity: Option<GetServiceByIdError> = serde_json::from_str(&content).ok();
122 Err(Error::ResponseError(ResponseContent { status, content, entity }))
123 }
124}
125
126pub async fn get_services(configuration: &configuration::Configuration, ) -> Result<models::ListWrapperService, Error<GetServicesError>> {
128
129 let uri_str = format!("{}/services", configuration.base_path);
130 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
131
132 if let Some(ref user_agent) = configuration.user_agent {
133 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
134 }
135 if let Some(ref token) = configuration.oauth_access_token {
136 req_builder = req_builder.bearer_auth(token.to_owned());
137 };
138
139 let req = req_builder.build()?;
140 let resp = configuration.client.execute(req).await?;
141
142 let status = resp.status();
143 let content_type = resp
144 .headers()
145 .get("content-type")
146 .and_then(|v| v.to_str().ok())
147 .unwrap_or("application/octet-stream");
148 let content_type = super::ContentType::from(content_type);
149
150 if !status.is_client_error() && !status.is_server_error() {
151 let content = resp.text().await?;
152 match content_type {
153 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
154 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWrapperService`"))),
155 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::ListWrapperService`")))),
156 }
157 } else {
158 let content = resp.text().await?;
159 let entity: Option<GetServicesError> = serde_json::from_str(&content).ok();
160 Err(Error::ResponseError(ResponseContent { status, content, entity }))
161 }
162}
163
164pub async fn post_service(configuration: &configuration::Configuration, new_service: models::NewService) -> Result<models::Service, Error<PostServiceError>> {
165 let p_new_service = new_service;
167
168 let uri_str = format!("{}/services", configuration.base_path);
169 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
170
171 if let Some(ref user_agent) = configuration.user_agent {
172 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
173 }
174 if let Some(ref token) = configuration.oauth_access_token {
175 req_builder = req_builder.bearer_auth(token.to_owned());
176 };
177 req_builder = req_builder.json(&p_new_service);
178
179 let req = req_builder.build()?;
180 let resp = configuration.client.execute(req).await?;
181
182 let status = resp.status();
183 let content_type = resp
184 .headers()
185 .get("content-type")
186 .and_then(|v| v.to_str().ok())
187 .unwrap_or("application/octet-stream");
188 let content_type = super::ContentType::from(content_type);
189
190 if !status.is_client_error() && !status.is_server_error() {
191 let content = resp.text().await?;
192 match content_type {
193 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
194 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Service`"))),
195 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::Service`")))),
196 }
197 } else {
198 let content = resp.text().await?;
199 let entity: Option<PostServiceError> = serde_json::from_str(&content).ok();
200 Err(Error::ResponseError(ResponseContent { status, content, entity }))
201 }
202}
203
204pub async fn put_service_by_id(configuration: &configuration::Configuration, id: &str, new_service: models::NewService) -> Result<models::Service, Error<PutServiceByIdError>> {
205 let p_id = id;
207 let p_new_service = new_service;
208
209 let uri_str = format!("{}/services/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
210 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
211
212 if let Some(ref user_agent) = configuration.user_agent {
213 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
214 }
215 if let Some(ref token) = configuration.oauth_access_token {
216 req_builder = req_builder.bearer_auth(token.to_owned());
217 };
218 req_builder = req_builder.json(&p_new_service);
219
220 let req = req_builder.build()?;
221 let resp = configuration.client.execute(req).await?;
222
223 let status = resp.status();
224 let content_type = resp
225 .headers()
226 .get("content-type")
227 .and_then(|v| v.to_str().ok())
228 .unwrap_or("application/octet-stream");
229 let content_type = super::ContentType::from(content_type);
230
231 if !status.is_client_error() && !status.is_server_error() {
232 let content = resp.text().await?;
233 match content_type {
234 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
235 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Service`"))),
236 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::Service`")))),
237 }
238 } else {
239 let content = resp.text().await?;
240 let entity: Option<PutServiceByIdError> = serde_json::from_str(&content).ok();
241 Err(Error::ResponseError(ResponseContent { status, content, entity }))
242 }
243}
244