p7m_appointment/apis/
availability_api.rs

1/*
2 * Appointments Backend
3 *
4 * # API for appointment scheduling related data  This is the API of the service at P7M that manages the scheduling and management of appointments. It is used by the booking widget (see the **WidgetApi** tag) with functions that are public and don't require the user to be authenticated.  For endpoints in other tags the caller has to be authenticated with the system and provide a JWT token in the Authorization header of the HTTP request. When using the API you typically get this token by authenticating first with OAuth 2.0.  When you are trying this API using the Swagger interface, you need to click the `Authorize` button and then again the Authorize button in the pop-up that gets opened.
5 *
6 * The version of the OpenAPI document: 0.13.5
7 * Contact: tech@p7m.de
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`delete_availability_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteAvailabilityByIdError {
22    Status400(),
23    Status404(),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`get_availabilities`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetAvailabilitiesError {
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`get_availability_by_id`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetAvailabilityByIdError {
38    Status404(),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`post_availabilities`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum PostAvailabilitiesError {
46    UnknownValue(serde_json::Value),
47}
48
49/// struct for typed errors of method [`put_availability_by_id`]
50#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum PutAvailabilityByIdError {
53    Status400(),
54    Status404(),
55    UnknownValue(serde_json::Value),
56}
57
58
59pub async fn delete_availability_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteAvailabilityByIdError>> {
60    // add a prefix to parameters to efficiently prevent name collisions
61    let p_id = id;
62
63    let uri_str = format!("{}/availabilities/{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<DeleteAvailabilityByIdError> = serde_json::from_str(&content).ok();
83        Err(Error::ResponseError(ResponseContent { status, content, entity }))
84    }
85}
86
87/// An availability is an amout of time where services can be booked for a worker (But may also already be booked)
88pub async fn get_availabilities(configuration: &configuration::Configuration, ) -> Result<models::ListWrapperAvailability, Error<GetAvailabilitiesError>> {
89
90    let uri_str = format!("{}/availabilities", configuration.base_path);
91    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
92
93    if let Some(ref user_agent) = configuration.user_agent {
94        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95    }
96    if let Some(ref token) = configuration.oauth_access_token {
97        req_builder = req_builder.bearer_auth(token.to_owned());
98    };
99
100    let req = req_builder.build()?;
101    let resp = configuration.client.execute(req).await?;
102
103    let status = resp.status();
104    let content_type = resp
105        .headers()
106        .get("content-type")
107        .and_then(|v| v.to_str().ok())
108        .unwrap_or("application/octet-stream");
109    let content_type = super::ContentType::from(content_type);
110
111    if !status.is_client_error() && !status.is_server_error() {
112        let content = resp.text().await?;
113        match content_type {
114            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
115            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWrapperAvailability`"))),
116            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::ListWrapperAvailability`")))),
117        }
118    } else {
119        let content = resp.text().await?;
120        let entity: Option<GetAvailabilitiesError> = serde_json::from_str(&content).ok();
121        Err(Error::ResponseError(ResponseContent { status, content, entity }))
122    }
123}
124
125pub async fn get_availability_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Availability, Error<GetAvailabilityByIdError>> {
126    // add a prefix to parameters to efficiently prevent name collisions
127    let p_id = id;
128
129    let uri_str = format!("{}/availabilities/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
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::Availability`"))),
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::Availability`")))),
156        }
157    } else {
158        let content = resp.text().await?;
159        let entity: Option<GetAvailabilityByIdError> = serde_json::from_str(&content).ok();
160        Err(Error::ResponseError(ResponseContent { status, content, entity }))
161    }
162}
163
164pub async fn post_availabilities(configuration: &configuration::Configuration, new_availability: models::NewAvailability) -> Result<models::Availability, Error<PostAvailabilitiesError>> {
165    // add a prefix to parameters to efficiently prevent name collisions
166    let p_new_availability = new_availability;
167
168    let uri_str = format!("{}/availabilities", 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_availability);
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::Availability`"))),
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::Availability`")))),
196        }
197    } else {
198        let content = resp.text().await?;
199        let entity: Option<PostAvailabilitiesError> = serde_json::from_str(&content).ok();
200        Err(Error::ResponseError(ResponseContent { status, content, entity }))
201    }
202}
203
204pub async fn put_availability_by_id(configuration: &configuration::Configuration, id: &str, new_availability: models::NewAvailability) -> Result<models::Availability, Error<PutAvailabilityByIdError>> {
205    // add a prefix to parameters to efficiently prevent name collisions
206    let p_id = id;
207    let p_new_availability = new_availability;
208
209    let uri_str = format!("{}/availabilities/{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_availability);
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::Availability`"))),
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::Availability`")))),
237        }
238    } else {
239        let content = resp.text().await?;
240        let entity: Option<PutAvailabilityByIdError> = serde_json::from_str(&content).ok();
241        Err(Error::ResponseError(ResponseContent { status, content, entity }))
242    }
243}
244