p7m_userauth/apis/
service_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 DeleteServicesSuperadminError {
22 Status401(),
23 Status403(),
24 UnknownValue(serde_json::Value),
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetServicesError {
31 Status401(),
32 Status403(),
33 UnknownValue(serde_json::Value),
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum PostServicesSuperadminError {
40 Status401(),
41 Status403(),
42 UnknownValue(serde_json::Value),
43}
44
45
46pub async fn delete_services_superadmin(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteServicesSuperadminError>> {
48 let p_id = id;
50
51 let uri_str = format!("{}/services/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
52 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
53
54 if let Some(ref user_agent) = configuration.user_agent {
55 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
56 }
57 if let Some(ref token) = configuration.oauth_access_token {
58 req_builder = req_builder.bearer_auth(token.to_owned());
59 };
60
61 let req = req_builder.build()?;
62 let resp = configuration.client.execute(req).await?;
63
64 let status = resp.status();
65
66 if !status.is_client_error() && !status.is_server_error() {
67 Ok(())
68 } else {
69 let content = resp.text().await?;
70 let entity: Option<DeleteServicesSuperadminError> = serde_json::from_str(&content).ok();
71 Err(Error::ResponseError(ResponseContent { status, content, entity }))
72 }
73}
74
75pub async fn get_services(configuration: &configuration::Configuration, ) -> Result<models::ListWrapperService, Error<GetServicesError>> {
76
77 let uri_str = format!("{}/services", configuration.base_path);
78 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
79
80 if let Some(ref user_agent) = configuration.user_agent {
81 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
82 }
83 if let Some(ref token) = configuration.oauth_access_token {
84 req_builder = req_builder.bearer_auth(token.to_owned());
85 };
86
87 let req = req_builder.build()?;
88 let resp = configuration.client.execute(req).await?;
89
90 let status = resp.status();
91 let content_type = resp
92 .headers()
93 .get("content-type")
94 .and_then(|v| v.to_str().ok())
95 .unwrap_or("application/octet-stream");
96 let content_type = super::ContentType::from(content_type);
97
98 if !status.is_client_error() && !status.is_server_error() {
99 let content = resp.text().await?;
100 match content_type {
101 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
102 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWrapperService`"))),
103 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::ListWrapperService`")))),
104 }
105 } else {
106 let content = resp.text().await?;
107 let entity: Option<GetServicesError> = serde_json::from_str(&content).ok();
108 Err(Error::ResponseError(ResponseContent { status, content, entity }))
109 }
110}
111
112pub async fn post_services_superadmin(configuration: &configuration::Configuration, new_service: models::NewService) -> Result<models::Service, Error<PostServicesSuperadminError>> {
114 let p_new_service = new_service;
116
117 let uri_str = format!("{}/services", configuration.base_path);
118 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
119
120 if let Some(ref user_agent) = configuration.user_agent {
121 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
122 }
123 if let Some(ref token) = configuration.oauth_access_token {
124 req_builder = req_builder.bearer_auth(token.to_owned());
125 };
126 req_builder = req_builder.json(&p_new_service);
127
128 let req = req_builder.build()?;
129 let resp = configuration.client.execute(req).await?;
130
131 let status = resp.status();
132 let content_type = resp
133 .headers()
134 .get("content-type")
135 .and_then(|v| v.to_str().ok())
136 .unwrap_or("application/octet-stream");
137 let content_type = super::ContentType::from(content_type);
138
139 if !status.is_client_error() && !status.is_server_error() {
140 let content = resp.text().await?;
141 match content_type {
142 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
143 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Service`"))),
144 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::Service`")))),
145 }
146 } else {
147 let content = resp.text().await?;
148 let entity: Option<PostServicesSuperadminError> = serde_json::from_str(&content).ok();
149 Err(Error::ResponseError(ResponseContent { status, content, entity }))
150 }
151}
152