osdm_sys/apis/
bookings_search_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 SearchBookingsError {
22 Status400(models::Problem),
23 Status401(models::Problem),
24 Status403(models::Problem),
25 Status404(models::Problem),
26 Status406(models::Problem),
27 Status415(models::Problem),
28 Status500(models::Problem),
29 Status501(models::Problem),
30 Status503(models::Problem),
31 DefaultResponse(models::Problem),
32 UnknownValue(serde_json::Value),
33}
34
35
36pub async fn search_bookings(configuration: &configuration::Configuration, booking_search_request: models::BookingSearchRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, x_accept_namespace: Option<&str>, page: Option<&str>) -> Result<models::BookingSearchResponse, Error<SearchBookingsError>> {
37 let p_body_booking_search_request = booking_search_request;
39 let p_header_requestor = requestor;
40 let p_header_accept_language = accept_language;
41 let p_header_traceparent = traceparent;
42 let p_header_tracestate = tracestate;
43 let p_header_x_accept_namespace = x_accept_namespace;
44 let p_query_page = page;
45
46 let uri_str = format!("{}/bookings-search", configuration.base_path);
47 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
48
49 if let Some(ref param_value) = p_query_page {
50 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
51 }
52 if let Some(ref user_agent) = configuration.user_agent {
53 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
54 }
55 if let Some(param_value) = p_header_requestor {
56 req_builder = req_builder.header("Requestor", param_value.to_string());
57 }
58 if let Some(param_value) = p_header_accept_language {
59 req_builder = req_builder.header("Accept-Language", param_value.to_string());
60 }
61 if let Some(param_value) = p_header_traceparent {
62 req_builder = req_builder.header("traceparent", param_value.to_string());
63 }
64 if let Some(param_value) = p_header_tracestate {
65 req_builder = req_builder.header("tracestate", param_value.to_string());
66 }
67 if let Some(param_value) = p_header_x_accept_namespace {
68 req_builder = req_builder.header("x-accept-namespace", param_value.to_string());
69 }
70 if let Some(ref token) = configuration.oauth_access_token {
71 req_builder = req_builder.bearer_auth(token.to_owned());
72 };
73 req_builder = req_builder.json(&p_body_booking_search_request);
74
75 let req = req_builder.build()?;
76 let resp = configuration.client.execute(req).await?;
77
78 let status = resp.status();
79 let content_type = resp
80 .headers()
81 .get("content-type")
82 .and_then(|v| v.to_str().ok())
83 .unwrap_or("application/octet-stream");
84 let content_type = super::ContentType::from(content_type);
85
86 if !status.is_client_error() && !status.is_server_error() {
87 let content = resp.text().await?;
88 match content_type {
89 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
90 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BookingSearchResponse`"))),
91 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::BookingSearchResponse`")))),
92 }
93 } else {
94 let content = resp.text().await?;
95 let entity: Option<SearchBookingsError> = serde_json::from_str(&content).ok();
96 Err(Error::ResponseError(ResponseContent { status, content, entity }))
97 }
98}
99