use super::ResponseContent;
use super::{ContentType, Error, configuration};
use crate::models;
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateResultError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteResultError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteResultsError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetResultError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListResultsError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateResultError {
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
pub fn create_result(
configuration: &configuration::Configuration,
result_model: models::ResultModel,
) -> Result<models::ResultModel, Error<CreateResultError>> {
let p_body_result_model = result_model;
let uri_str = format!("{}/results", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
req_builder = req_builder.json(&p_body_result_model);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::ResultModel`",
)));
}
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::ResultModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<CreateResultError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn delete_result(
configuration: &configuration::Configuration,
id: i64,
) -> Result<models::ResultModel, Error<DeleteResultError>> {
let p_path_id = id;
let uri_str = format!("{}/results/{id}", configuration.base_path, id = p_path_id);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::ResultModel`",
)));
}
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::ResultModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<DeleteResultError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn delete_results(
configuration: &configuration::Configuration,
workflow_id: i64,
) -> Result<serde_json::Value, Error<DeleteResultsError>> {
let p_query_workflow_id = workflow_id;
let uri_str = format!("{}/results", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
req_builder = req_builder.query(&[("workflow_id", &p_query_workflow_id.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `serde_json::Value`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<DeleteResultsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn get_result(
configuration: &configuration::Configuration,
id: i64,
) -> Result<models::ResultModel, Error<GetResultError>> {
let p_path_id = id;
let uri_str = format!("{}/results/{id}", configuration.base_path, id = p_path_id);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::ResultModel`",
)));
}
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::ResultModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<GetResultError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn list_results(
configuration: &configuration::Configuration,
workflow_id: i64,
job_id: Option<i64>,
run_id: Option<i64>,
return_code: Option<i64>,
status: Option<models::JobStatus>,
compute_node_id: Option<i64>,
offset: Option<i64>,
limit: Option<i64>,
sort_by: Option<&str>,
reverse_sort: Option<bool>,
all_runs: Option<bool>,
) -> Result<models::ListResultsResponse, Error<ListResultsError>> {
let p_query_workflow_id = workflow_id;
let p_query_job_id = job_id;
let p_query_run_id = run_id;
let p_query_return_code = return_code;
let p_query_status = status;
let p_query_compute_node_id = compute_node_id;
let p_query_offset = offset;
let p_query_limit = limit;
let p_query_sort_by = sort_by;
let p_query_reverse_sort = reverse_sort;
let p_query_all_runs = all_runs;
let uri_str = format!("{}/results", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("workflow_id", &p_query_workflow_id.to_string())]);
if let Some(ref param_value) = p_query_job_id {
req_builder = req_builder.query(&[("job_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_run_id {
req_builder = req_builder.query(&[("run_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_return_code {
req_builder = req_builder.query(&[("return_code", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_status {
req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_compute_node_id {
req_builder = req_builder.query(&[("compute_node_id", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_sort_by {
req_builder = req_builder.query(&[("sort_by", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_reverse_sort {
req_builder = req_builder.query(&[("reverse_sort", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_all_runs {
req_builder = req_builder.query(&[("all_runs", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::ListResultsResponse`",
)));
}
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::ListResultsResponse`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<ListResultsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn update_result(
configuration: &configuration::Configuration,
id: i64,
result_model: models::ResultModel,
) -> Result<models::ResultModel, Error<UpdateResultError>> {
let p_path_id = id;
let p_body_result_model = result_model;
let uri_str = format!("{}/results/{id}", configuration.base_path, id = p_path_id);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = configuration.apply_auth(req_builder);
req_builder = req_builder.json(&p_body_result_model);
let req = req_builder.build()?;
let resp = configuration.client.execute(req)?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text()?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::ResultModel`",
)));
}
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::ResultModel`"
))));
}
}
} else {
let content = resp.text()?;
let entity: Option<UpdateResultError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}