geoengine_api_client/apis/
tasks_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 AbortHandlerError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ListHandlerError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum StatusHandlerError {
36 UnknownValue(serde_json::Value),
37}
38
39
40pub async fn abort_handler(configuration: &configuration::Configuration, id: &str, force: Option<bool>) -> Result<(), Error<AbortHandlerError>> {
42 let p_path_id = id;
44 let p_query_force = force;
45
46 let uri_str = format!("{}/tasks/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
47 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
48
49 if let Some(ref param_value) = p_query_force {
50 req_builder = req_builder.query(&[("force", ¶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(ref token) = configuration.bearer_access_token {
56 req_builder = req_builder.bearer_auth(token.to_owned());
57 };
58
59 let req = req_builder.build()?;
60 let resp = configuration.client.execute(req).await?;
61
62 let status = resp.status();
63
64 if !status.is_client_error() && !status.is_server_error() {
65 Ok(())
66 } else {
67 let content = resp.text().await?;
68 let entity: Option<AbortHandlerError> = serde_json::from_str(&content).ok();
69 Err(Error::ResponseError(ResponseContent { status, content, entity }))
70 }
71}
72
73pub async fn list_handler(configuration: &configuration::Configuration, filter: Option<&str>, offset: i32, limit: i32) -> Result<Vec<models::TaskStatusWithId>, Error<ListHandlerError>> {
74 let p_path_filter = filter;
76 let p_path_offset = offset;
77 let p_path_limit = limit;
78
79 let uri_str = format!(
80 "{}/tasks/list?filter={}&offset={}&limit={}",
81 configuration.base_path,
82 p_path_filter.unwrap().to_string(),
83 p_path_offset,
84 p_path_limit
85 );
86 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
87
88 if let Some(ref user_agent) = configuration.user_agent {
89 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
90 }
91 if let Some(ref token) = configuration.bearer_access_token {
92 req_builder = req_builder.bearer_auth(token.to_owned());
93 };
94
95 let req = req_builder.build()?;
96 let resp = configuration.client.execute(req).await?;
97
98 let status = resp.status();
99 let content_type = resp
100 .headers()
101 .get("content-type")
102 .and_then(|v| v.to_str().ok())
103 .unwrap_or("application/octet-stream");
104 let content_type = super::ContentType::from(content_type);
105
106 if !status.is_client_error() && !status.is_server_error() {
107 let content = resp.text().await?;
108 match content_type {
109 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
110 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::TaskStatusWithId>`"))),
111 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::TaskStatusWithId>`")))),
112 }
113 } else {
114 let content = resp.text().await?;
115 let entity: Option<ListHandlerError> = serde_json::from_str(&content).ok();
116 Err(Error::ResponseError(ResponseContent { status, content, entity }))
117 }
118}
119
120pub async fn status_handler(configuration: &configuration::Configuration, id: &str) -> Result<models::TaskStatus, Error<StatusHandlerError>> {
121 let p_path_id = id;
123
124 let uri_str = format!("{}/tasks/{id}/status", configuration.base_path, id=crate::apis::urlencode(p_path_id));
125 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
126
127 if let Some(ref user_agent) = configuration.user_agent {
128 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
129 }
130 if let Some(ref token) = configuration.bearer_access_token {
131 req_builder = req_builder.bearer_auth(token.to_owned());
132 };
133
134 let req = req_builder.build()?;
135 let resp = configuration.client.execute(req).await?;
136
137 let status = resp.status();
138 let content_type = resp
139 .headers()
140 .get("content-type")
141 .and_then(|v| v.to_str().ok())
142 .unwrap_or("application/octet-stream");
143 let content_type = super::ContentType::from(content_type);
144
145 if !status.is_client_error() && !status.is_server_error() {
146 let content = resp.text().await?;
147 match content_type {
148 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
149 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TaskStatus`"))),
150 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::TaskStatus`")))),
151 }
152 } else {
153 let content = resp.text().await?;
154 let entity: Option<StatusHandlerError> = serde_json::from_str(&content).ok();
155 Err(Error::ResponseError(ResponseContent { status, content, entity }))
156 }
157}
158