p7m_appointment/apis/
reservation_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_reservation_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteReservationByIdError {
22    Status400(),
23    Status404(),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`get_reservations`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetReservationsError {
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`get_reservations_by_id`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetReservationsByIdError {
38    Status404(),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`post_reservations`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum PostReservationsError {
46    UnknownValue(serde_json::Value),
47}
48
49/// struct for typed errors of method [`put_reservation_by_id`]
50#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum PutReservationByIdError {
53    Status400(),
54    Status404(),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`put_reservation_tags_by_id`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum PutReservationTagsByIdError {
62    Status400(),
63    Status404(),
64    UnknownValue(serde_json::Value),
65}
66
67
68pub async fn delete_reservation_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteReservationByIdError>> {
69    // add a prefix to parameters to efficiently prevent name collisions
70    let p_id = id;
71
72    let uri_str = format!("{}/reservations/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
73    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
74
75    if let Some(ref user_agent) = configuration.user_agent {
76        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
77    }
78    if let Some(ref token) = configuration.oauth_access_token {
79        req_builder = req_builder.bearer_auth(token.to_owned());
80    };
81
82    let req = req_builder.build()?;
83    let resp = configuration.client.execute(req).await?;
84
85    let status = resp.status();
86
87    if !status.is_client_error() && !status.is_server_error() {
88        Ok(())
89    } else {
90        let content = resp.text().await?;
91        let entity: Option<DeleteReservationByIdError> = serde_json::from_str(&content).ok();
92        Err(Error::ResponseError(ResponseContent { status, content, entity }))
93    }
94}
95
96/// A reservation is an amount of time booked by a patient or blocked by the tenant
97pub async fn get_reservations(configuration: &configuration::Configuration, start_time_min: Option<String>, start_time_max: Option<String>, tag_id: Option<&str>) -> Result<models::ListWrapperReservation, Error<GetReservationsError>> {
98    // add a prefix to parameters to efficiently prevent name collisions
99    let p_start_time_min = start_time_min;
100    let p_start_time_max = start_time_max;
101    let p_tag_id = tag_id;
102
103    let uri_str = format!("{}/reservations", configuration.base_path);
104    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
105
106    if let Some(ref param_value) = p_start_time_min {
107        req_builder = req_builder.query(&[("startTimeMin", &param_value.to_string())]);
108    }
109    if let Some(ref param_value) = p_start_time_max {
110        req_builder = req_builder.query(&[("startTimeMax", &param_value.to_string())]);
111    }
112    if let Some(ref param_value) = p_tag_id {
113        req_builder = req_builder.query(&[("tagId", &param_value.to_string())]);
114    }
115    if let Some(ref user_agent) = configuration.user_agent {
116        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
117    }
118    if let Some(ref token) = configuration.oauth_access_token {
119        req_builder = req_builder.bearer_auth(token.to_owned());
120    };
121
122    let req = req_builder.build()?;
123    let resp = configuration.client.execute(req).await?;
124
125    let status = resp.status();
126    let content_type = resp
127        .headers()
128        .get("content-type")
129        .and_then(|v| v.to_str().ok())
130        .unwrap_or("application/octet-stream");
131    let content_type = super::ContentType::from(content_type);
132
133    if !status.is_client_error() && !status.is_server_error() {
134        let content = resp.text().await?;
135        match content_type {
136            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
137            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWrapperReservation`"))),
138            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::ListWrapperReservation`")))),
139        }
140    } else {
141        let content = resp.text().await?;
142        let entity: Option<GetReservationsError> = serde_json::from_str(&content).ok();
143        Err(Error::ResponseError(ResponseContent { status, content, entity }))
144    }
145}
146
147pub async fn get_reservations_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Reservation, Error<GetReservationsByIdError>> {
148    // add a prefix to parameters to efficiently prevent name collisions
149    let p_id = id;
150
151    let uri_str = format!("{}/reservations/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
152    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
153
154    if let Some(ref user_agent) = configuration.user_agent {
155        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
156    }
157    if let Some(ref token) = configuration.oauth_access_token {
158        req_builder = req_builder.bearer_auth(token.to_owned());
159    };
160
161    let req = req_builder.build()?;
162    let resp = configuration.client.execute(req).await?;
163
164    let status = resp.status();
165    let content_type = resp
166        .headers()
167        .get("content-type")
168        .and_then(|v| v.to_str().ok())
169        .unwrap_or("application/octet-stream");
170    let content_type = super::ContentType::from(content_type);
171
172    if !status.is_client_error() && !status.is_server_error() {
173        let content = resp.text().await?;
174        match content_type {
175            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
176            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Reservation`"))),
177            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::Reservation`")))),
178        }
179    } else {
180        let content = resp.text().await?;
181        let entity: Option<GetReservationsByIdError> = serde_json::from_str(&content).ok();
182        Err(Error::ResponseError(ResponseContent { status, content, entity }))
183    }
184}
185
186pub async fn post_reservations(configuration: &configuration::Configuration, new_reservation: models::NewReservation) -> Result<models::Reservation, Error<PostReservationsError>> {
187    // add a prefix to parameters to efficiently prevent name collisions
188    let p_new_reservation = new_reservation;
189
190    let uri_str = format!("{}/reservations", configuration.base_path);
191    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
192
193    if let Some(ref user_agent) = configuration.user_agent {
194        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
195    }
196    if let Some(ref token) = configuration.oauth_access_token {
197        req_builder = req_builder.bearer_auth(token.to_owned());
198    };
199    req_builder = req_builder.json(&p_new_reservation);
200
201    let req = req_builder.build()?;
202    let resp = configuration.client.execute(req).await?;
203
204    let status = resp.status();
205    let content_type = resp
206        .headers()
207        .get("content-type")
208        .and_then(|v| v.to_str().ok())
209        .unwrap_or("application/octet-stream");
210    let content_type = super::ContentType::from(content_type);
211
212    if !status.is_client_error() && !status.is_server_error() {
213        let content = resp.text().await?;
214        match content_type {
215            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
216            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Reservation`"))),
217            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::Reservation`")))),
218        }
219    } else {
220        let content = resp.text().await?;
221        let entity: Option<PostReservationsError> = serde_json::from_str(&content).ok();
222        Err(Error::ResponseError(ResponseContent { status, content, entity }))
223    }
224}
225
226pub async fn put_reservation_by_id(configuration: &configuration::Configuration, id: &str, reservation: models::Reservation) -> Result<models::Reservation, Error<PutReservationByIdError>> {
227    // add a prefix to parameters to efficiently prevent name collisions
228    let p_id = id;
229    let p_reservation = reservation;
230
231    let uri_str = format!("{}/reservations/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
232    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
233
234    if let Some(ref user_agent) = configuration.user_agent {
235        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
236    }
237    if let Some(ref token) = configuration.oauth_access_token {
238        req_builder = req_builder.bearer_auth(token.to_owned());
239    };
240    req_builder = req_builder.json(&p_reservation);
241
242    let req = req_builder.build()?;
243    let resp = configuration.client.execute(req).await?;
244
245    let status = resp.status();
246    let content_type = resp
247        .headers()
248        .get("content-type")
249        .and_then(|v| v.to_str().ok())
250        .unwrap_or("application/octet-stream");
251    let content_type = super::ContentType::from(content_type);
252
253    if !status.is_client_error() && !status.is_server_error() {
254        let content = resp.text().await?;
255        match content_type {
256            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
257            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Reservation`"))),
258            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::Reservation`")))),
259        }
260    } else {
261        let content = resp.text().await?;
262        let entity: Option<PutReservationByIdError> = serde_json::from_str(&content).ok();
263        Err(Error::ResponseError(ResponseContent { status, content, entity }))
264    }
265}
266
267pub async fn put_reservation_tags_by_id(configuration: &configuration::Configuration, id: &str, uuid_colon_colon_uuid: Vec<uuid::Uuid>) -> Result<models::Reservation, Error<PutReservationTagsByIdError>> {
268    // add a prefix to parameters to efficiently prevent name collisions
269    let p_id = id;
270    let p_uuid_colon_colon_uuid = uuid_colon_colon_uuid;
271
272    let uri_str = format!("{}/reservations/{id}/tags", configuration.base_path, id=crate::apis::urlencode(p_id));
273    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
274
275    if let Some(ref user_agent) = configuration.user_agent {
276        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
277    }
278    if let Some(ref token) = configuration.oauth_access_token {
279        req_builder = req_builder.bearer_auth(token.to_owned());
280    };
281    req_builder = req_builder.json(&p_uuid_colon_colon_uuid);
282
283    let req = req_builder.build()?;
284    let resp = configuration.client.execute(req).await?;
285
286    let status = resp.status();
287    let content_type = resp
288        .headers()
289        .get("content-type")
290        .and_then(|v| v.to_str().ok())
291        .unwrap_or("application/octet-stream");
292    let content_type = super::ContentType::from(content_type);
293
294    if !status.is_client_error() && !status.is_server_error() {
295        let content = resp.text().await?;
296        match content_type {
297            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
298            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Reservation`"))),
299            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::Reservation`")))),
300        }
301    } else {
302        let content = resp.text().await?;
303        let entity: Option<PutReservationTagsByIdError> = serde_json::from_str(&content).ok();
304        Err(Error::ResponseError(ResponseContent { status, content, entity }))
305    }
306}
307