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