p7m_appointment/apis/
widget_api_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 [`get_booking_config`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetBookingConfigError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_booking_schedule`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetBookingScheduleError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`post_booking_reserve`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum PostBookingReserveError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`post_booking_reserve_confirmation`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PostBookingReserveConfirmationError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`put_booking_reserve_by_id`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PutBookingReserveByIdError {
50    UnknownValue(serde_json::Value),
51}
52
53
54/// It is the entry point for the widget. The widget only needs to know in the page of which tenant it is used, then it sends out a request to this endpoint to know its basic configuration, services and workers it can offer to the user.
55pub async fn get_booking_config(configuration: &configuration::Configuration, id: &str) -> Result<models::TenantConfig, Error<GetBookingConfigError>> {
56    // add a prefix to parameters to efficiently prevent name collisions
57    let p_id = id;
58
59    let uri_str = format!("{}/booking/config/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
60    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
61
62    if let Some(ref user_agent) = configuration.user_agent {
63        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
64    }
65
66    let req = req_builder.build()?;
67    let resp = configuration.client.execute(req).await?;
68
69    let status = resp.status();
70    let content_type = resp
71        .headers()
72        .get("content-type")
73        .and_then(|v| v.to_str().ok())
74        .unwrap_or("application/octet-stream");
75    let content_type = super::ContentType::from(content_type);
76
77    if !status.is_client_error() && !status.is_server_error() {
78        let content = resp.text().await?;
79        match content_type {
80            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
81            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TenantConfig`"))),
82            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::TenantConfig`")))),
83        }
84    } else {
85        let content = resp.text().await?;
86        let entity: Option<GetBookingConfigError> = serde_json::from_str(&content).ok();
87        Err(Error::ResponseError(ResponseContent { status, content, entity }))
88    }
89}
90
91/// After the user has selected a service and a worker, the Widget will use this endpoint to request the time slots it can provide to the user. Time slots are requested by date.
92pub async fn get_booking_schedule(configuration: &configuration::Configuration, tid: &str, sid: &str, wid: &str, date: String) -> Result<models::Availabilities, Error<GetBookingScheduleError>> {
93    // add a prefix to parameters to efficiently prevent name collisions
94    let p_tid = tid;
95    let p_sid = sid;
96    let p_wid = wid;
97    let p_date = date;
98
99    let uri_str = format!("{}/booking/schedule/{tid}/{sid}/{wid}/{date}", configuration.base_path, tid=crate::apis::urlencode(p_tid), sid=crate::apis::urlencode(p_sid), wid=crate::apis::urlencode(p_wid), date=p_date);
100    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
101
102    if let Some(ref user_agent) = configuration.user_agent {
103        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
104    }
105
106    let req = req_builder.build()?;
107    let resp = configuration.client.execute(req).await?;
108
109    let status = resp.status();
110    let content_type = resp
111        .headers()
112        .get("content-type")
113        .and_then(|v| v.to_str().ok())
114        .unwrap_or("application/octet-stream");
115    let content_type = super::ContentType::from(content_type);
116
117    if !status.is_client_error() && !status.is_server_error() {
118        let content = resp.text().await?;
119        match content_type {
120            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
121            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Availabilities`"))),
122            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::Availabilities`")))),
123        }
124    } else {
125        let content = resp.text().await?;
126        let entity: Option<GetBookingScheduleError> = serde_json::from_str(&content).ok();
127        Err(Error::ResponseError(ResponseContent { status, content, entity }))
128    }
129}
130
131/// After the user has selected a time slot, that it wants to use, the widget will use this endpoint to reserve the given time slot. The server will check, whether the slot is still available, send out the verification code to the user by SMS or phone call, and return to the caller whether the slot could be reserved.  For final booking of the time slot, the user has to give the widget the PIN it got sent, and the widget has to send the PIN with another request to the server, to finally book the reservation it made. Reservations, that do not get booked, will be canceled after a configured amount of time.  **Note:** This endpoint is especially purposed for the self-service of the user using the booking widget, therefore a reservation created here will be stored with a source type of `WEB`.
132pub async fn post_booking_reserve(configuration: &configuration::Configuration, reservation_request: models::ReservationRequest) -> Result<models::ReservationResponse, Error<PostBookingReserveError>> {
133    // add a prefix to parameters to efficiently prevent name collisions
134    let p_reservation_request = reservation_request;
135
136    let uri_str = format!("{}/booking/reserve", configuration.base_path);
137    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
138
139    if let Some(ref user_agent) = configuration.user_agent {
140        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
141    }
142    req_builder = req_builder.json(&p_reservation_request);
143
144    let req = req_builder.build()?;
145    let resp = configuration.client.execute(req).await?;
146
147    let status = resp.status();
148    let content_type = resp
149        .headers()
150        .get("content-type")
151        .and_then(|v| v.to_str().ok())
152        .unwrap_or("application/octet-stream");
153    let content_type = super::ContentType::from(content_type);
154
155    if !status.is_client_error() && !status.is_server_error() {
156        let content = resp.text().await?;
157        match content_type {
158            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
159            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReservationResponse`"))),
160            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::ReservationResponse`")))),
161        }
162    } else {
163        let content = resp.text().await?;
164        let entity: Option<PostBookingReserveError> = serde_json::from_str(&content).ok();
165        Err(Error::ResponseError(ResponseContent { status, content, entity }))
166    }
167}
168
169/// After the user has entered the PIN he received in the Widget, the widget has to send the PIN to the server using this function. On the one hand this will confirm the reservation to the server, and on the other hand will tell the widget whether the entered PIN has been correct.
170pub async fn post_booking_reserve_confirmation(configuration: &configuration::Configuration, rid: &str, confirmation_request: models::ConfirmationRequest) -> Result<models::ConfirmationResponse, Error<PostBookingReserveConfirmationError>> {
171    // add a prefix to parameters to efficiently prevent name collisions
172    let p_rid = rid;
173    let p_confirmation_request = confirmation_request;
174
175    let uri_str = format!("{}/booking/reserve/{rid}/confirmation", configuration.base_path, rid=crate::apis::urlencode(p_rid));
176    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
177
178    if let Some(ref user_agent) = configuration.user_agent {
179        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
180    }
181    req_builder = req_builder.json(&p_confirmation_request);
182
183    let req = req_builder.build()?;
184    let resp = configuration.client.execute(req).await?;
185
186    let status = resp.status();
187    let content_type = resp
188        .headers()
189        .get("content-type")
190        .and_then(|v| v.to_str().ok())
191        .unwrap_or("application/octet-stream");
192    let content_type = super::ContentType::from(content_type);
193
194    if !status.is_client_error() && !status.is_server_error() {
195        let content = resp.text().await?;
196        match content_type {
197            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
198            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfirmationResponse`"))),
199            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::ConfirmationResponse`")))),
200        }
201    } else {
202        let content = resp.text().await?;
203        let entity: Option<PostBookingReserveConfirmationError> = serde_json::from_str(&content).ok();
204        Err(Error::ResponseError(ResponseContent { status, content, entity }))
205    }
206}
207
208/// TODO: Use this endpoint also to allow updating a revervation
209pub async fn put_booking_reserve_by_id(configuration: &configuration::Configuration, rid: &str, reservation_request: models::ReservationRequest) -> Result<models::ReservationResponse, Error<PutBookingReserveByIdError>> {
210    // add a prefix to parameters to efficiently prevent name collisions
211    let p_rid = rid;
212    let p_reservation_request = reservation_request;
213
214    let uri_str = format!("{}/booking/reserve/{rid}", configuration.base_path, rid=crate::apis::urlencode(p_rid));
215    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
216
217    if let Some(ref user_agent) = configuration.user_agent {
218        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
219    }
220    req_builder = req_builder.json(&p_reservation_request);
221
222    let req = req_builder.build()?;
223    let resp = configuration.client.execute(req).await?;
224
225    let status = resp.status();
226    let content_type = resp
227        .headers()
228        .get("content-type")
229        .and_then(|v| v.to_str().ok())
230        .unwrap_or("application/octet-stream");
231    let content_type = super::ContentType::from(content_type);
232
233    if !status.is_client_error() && !status.is_server_error() {
234        let content = resp.text().await?;
235        match content_type {
236            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
237            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReservationResponse`"))),
238            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::ReservationResponse`")))),
239        }
240    } else {
241        let content = resp.text().await?;
242        let entity: Option<PutBookingReserveByIdError> = serde_json::from_str(&content).ok();
243        Err(Error::ResponseError(ResponseContent { status, content, entity }))
244    }
245}
246