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 AddOrganisationError {
22 Status403(models::UnauthorizedApiError),
23 Status404(models::NotFoundApiError),
24 DefaultResponse(models::ApiError),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DeleteOrganisationError {
32 Status403(models::UnauthorizedApiError),
33 Status404(models::NotFoundApiError),
34 DefaultResponse(models::ApiError),
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum EditOrganisationError {
42 Status403(models::UnauthorizedApiError),
43 Status404(models::NotFoundApiError),
44 DefaultResponse(models::ApiError),
45 UnknownValue(serde_json::Value),
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetOrganisationByIdError {
52 Status403(models::UnauthorizedApiError),
53 Status404(models::NotFoundApiError),
54 DefaultResponse(models::ApiError),
55 UnknownValue(serde_json::Value),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum GetOrganisationsError {
62 Status403(models::UnauthorizedApiError),
63 Status404(models::NotFoundApiError),
64 DefaultResponse(models::ApiError),
65 UnknownValue(serde_json::Value),
66}
67
68
69pub async fn add_organisation(configuration: &configuration::Configuration, organisation_no_id: Option<models::OrganisationNoId>) -> Result<models::Organisation, Error<AddOrganisationError>> {
70 let p_organisation_no_id = organisation_no_id;
72
73 let uri_str = format!("{}/admin/organisations/add", configuration.base_path);
74 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
75
76 if let Some(ref user_agent) = configuration.user_agent {
77 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
78 }
79 if let Some(ref apikey) = configuration.api_key {
80 let key = apikey.key.clone();
81 let value = match apikey.prefix {
82 Some(ref prefix) => format!("{} {}", prefix, key),
83 None => key,
84 };
85 req_builder = req_builder.header("Authorization", value);
86 };
87 req_builder = req_builder.json(&p_organisation_no_id);
88
89 let req = req_builder.build()?;
90 let resp = configuration.client.execute(req).await?;
91
92 let status = resp.status();
93 let content_type = resp
94 .headers()
95 .get("content-type")
96 .and_then(|v| v.to_str().ok())
97 .unwrap_or("application/octet-stream");
98 let content_type = super::ContentType::from(content_type);
99
100 if !status.is_client_error() && !status.is_server_error() {
101 let content = resp.text().await?;
102 match content_type {
103 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
104 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Organisation`"))),
105 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::Organisation`")))),
106 }
107 } else {
108 let content = resp.text().await?;
109 let entity: Option<AddOrganisationError> = serde_json::from_str(&content).ok();
110 Err(Error::ResponseError(ResponseContent { status, content, entity }))
111 }
112}
113
114pub async fn delete_organisation(configuration: &configuration::Configuration, organisation_id: &str) -> Result<models::DeleteOrganisation200Response, Error<DeleteOrganisationError>> {
115 let p_organisation_id = organisation_id;
117
118 let uri_str = format!("{}/admin/organisations/delete/{organisationId}", configuration.base_path, organisationId=p_organisation_id.to_string());
119 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
120
121 if let Some(ref user_agent) = configuration.user_agent {
122 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
123 }
124 if let Some(ref apikey) = configuration.api_key {
125 let key = apikey.key.clone();
126 let value = match apikey.prefix {
127 Some(ref prefix) => format!("{} {}", prefix, key),
128 None => key,
129 };
130 req_builder = req_builder.header("Authorization", value);
131 };
132
133 let req = req_builder.build()?;
134 let resp = configuration.client.execute(req).await?;
135
136 let status = resp.status();
137 let content_type = resp
138 .headers()
139 .get("content-type")
140 .and_then(|v| v.to_str().ok())
141 .unwrap_or("application/octet-stream");
142 let content_type = super::ContentType::from(content_type);
143
144 if !status.is_client_error() && !status.is_server_error() {
145 let content = resp.text().await?;
146 match content_type {
147 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
148 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteOrganisation200Response`"))),
149 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::DeleteOrganisation200Response`")))),
150 }
151 } else {
152 let content = resp.text().await?;
153 let entity: Option<DeleteOrganisationError> = serde_json::from_str(&content).ok();
154 Err(Error::ResponseError(ResponseContent { status, content, entity }))
155 }
156}
157
158pub async fn edit_organisation(configuration: &configuration::Configuration, organisation_id: &str, edit_organisation_request: Option<models::EditOrganisationRequest>) -> Result<models::Organisation, Error<EditOrganisationError>> {
159 let p_organisation_id = organisation_id;
161 let p_edit_organisation_request = edit_organisation_request;
162
163 let uri_str = format!("{}/admin/organisations/edit/{organisationId}", configuration.base_path, organisationId=p_organisation_id.to_string());
164 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
165
166 if let Some(ref user_agent) = configuration.user_agent {
167 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
168 }
169 if let Some(ref apikey) = configuration.api_key {
170 let key = apikey.key.clone();
171 let value = match apikey.prefix {
172 Some(ref prefix) => format!("{} {}", prefix, key),
173 None => key,
174 };
175 req_builder = req_builder.header("Authorization", value);
176 };
177 req_builder = req_builder.json(&p_edit_organisation_request);
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::Organisation`"))),
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::Organisation`")))),
196 }
197 } else {
198 let content = resp.text().await?;
199 let entity: Option<EditOrganisationError> = serde_json::from_str(&content).ok();
200 Err(Error::ResponseError(ResponseContent { status, content, entity }))
201 }
202}
203
204pub async fn get_organisation_by_id(configuration: &configuration::Configuration, organisation_id: &str) -> Result<models::Organisation, Error<GetOrganisationByIdError>> {
205 let p_organisation_id = organisation_id;
207
208 let uri_str = format!("{}/organisations/view/{organisationId}", configuration.base_path, organisationId=p_organisation_id.to_string());
209 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
210
211 if let Some(ref user_agent) = configuration.user_agent {
212 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
213 }
214 if let Some(ref apikey) = configuration.api_key {
215 let key = apikey.key.clone();
216 let value = match apikey.prefix {
217 Some(ref prefix) => format!("{} {}", prefix, key),
218 None => key,
219 };
220 req_builder = req_builder.header("Authorization", value);
221 };
222
223 let req = req_builder.build()?;
224 let resp = configuration.client.execute(req).await?;
225
226 let status = resp.status();
227 let content_type = resp
228 .headers()
229 .get("content-type")
230 .and_then(|v| v.to_str().ok())
231 .unwrap_or("application/octet-stream");
232 let content_type = super::ContentType::from(content_type);
233
234 if !status.is_client_error() && !status.is_server_error() {
235 let content = resp.text().await?;
236 match content_type {
237 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
238 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Organisation`"))),
239 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::Organisation`")))),
240 }
241 } else {
242 let content = resp.text().await?;
243 let entity: Option<GetOrganisationByIdError> = serde_json::from_str(&content).ok();
244 Err(Error::ResponseError(ResponseContent { status, content, entity }))
245 }
246}
247
248pub async fn get_organisations(configuration: &configuration::Configuration, ) -> Result<Vec<models::OrganisationListItem>, Error<GetOrganisationsError>> {
249
250 let uri_str = format!("{}/organisations", configuration.base_path);
251 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
252
253 if let Some(ref user_agent) = configuration.user_agent {
254 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
255 }
256 if let Some(ref apikey) = configuration.api_key {
257 let key = apikey.key.clone();
258 let value = match apikey.prefix {
259 Some(ref prefix) => format!("{} {}", prefix, key),
260 None => key,
261 };
262 req_builder = req_builder.header("Authorization", value);
263 };
264
265 let req = req_builder.build()?;
266 let resp = configuration.client.execute(req).await?;
267
268 let status = resp.status();
269 let content_type = resp
270 .headers()
271 .get("content-type")
272 .and_then(|v| v.to_str().ok())
273 .unwrap_or("application/octet-stream");
274 let content_type = super::ContentType::from(content_type);
275
276 if !status.is_client_error() && !status.is_server_error() {
277 let content = resp.text().await?;
278 match content_type {
279 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
280 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::OrganisationListItem>`"))),
281 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::OrganisationListItem>`")))),
282 }
283 } else {
284 let content = resp.text().await?;
285 let entity: Option<GetOrganisationsError> = serde_json::from_str(&content).ok();
286 Err(Error::ResponseError(ResponseContent { status, content, entity }))
287 }
288}
289