lance_namespace_reqwest_client/apis/
transaction_api.rs

1/*
2 * Lance Namespace Specification
3 *
4 * This OpenAPI specification is a part of the Lance namespace specification. It contains 2 parts:  The `components/schemas`, `components/responses`, `components/examples`, `tags` sections define the request and response shape for each operation in a Lance Namespace across all implementations. See https://lance.org/format/namespace/operations for more details.  The `servers`, `security`, `paths`, `components/parameters` sections are for the  Lance REST Namespace implementation, which defines a complete REST server that can work with Lance datasets. See https://lance.org/format/namespace/rest for more details. 
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`alter_transaction`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AlterTransactionError {
22    Status400(models::ErrorResponse),
23    Status401(models::ErrorResponse),
24    Status403(models::ErrorResponse),
25    Status404(models::ErrorResponse),
26    Status409(models::ErrorResponse),
27    Status503(models::ErrorResponse),
28    Status5XX(models::ErrorResponse),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`describe_transaction`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum DescribeTransactionError {
36    Status400(models::ErrorResponse),
37    Status401(models::ErrorResponse),
38    Status403(models::ErrorResponse),
39    Status404(models::ErrorResponse),
40    Status503(models::ErrorResponse),
41    Status5XX(models::ErrorResponse),
42    UnknownValue(serde_json::Value),
43}
44
45
46/// Alter a transaction with a list of actions such as setting status or properties. The server should either succeed and apply all actions, or fail and apply no action. 
47pub async fn alter_transaction(configuration: &configuration::Configuration, id: &str, alter_transaction_request: models::AlterTransactionRequest, delimiter: Option<&str>) -> Result<models::AlterTransactionResponse, Error<AlterTransactionError>> {
48    // add a prefix to parameters to efficiently prevent name collisions
49    let p_id = id;
50    let p_alter_transaction_request = alter_transaction_request;
51    let p_delimiter = delimiter;
52
53    let uri_str = format!("{}/v1/transaction/{id}/alter", configuration.base_path, id=crate::apis::urlencode(p_id));
54    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
55
56    if let Some(ref param_value) = p_delimiter {
57        req_builder = req_builder.query(&[("delimiter", &param_value.to_string())]);
58    }
59    if let Some(ref user_agent) = configuration.user_agent {
60        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
61    }
62    if let Some(ref token) = configuration.oauth_access_token {
63        req_builder = req_builder.bearer_auth(token.to_owned());
64    };
65    if let Some(ref apikey) = configuration.api_key {
66        let key = apikey.key.clone();
67        let value = match apikey.prefix {
68            Some(ref prefix) => format!("{} {}", prefix, key),
69            None => key,
70        };
71        req_builder = req_builder.header("x-api-key", value);
72    };
73    if let Some(ref token) = configuration.bearer_access_token {
74        req_builder = req_builder.bearer_auth(token.to_owned());
75    };
76    req_builder = req_builder.json(&p_alter_transaction_request);
77
78    let req = req_builder.build()?;
79    let resp = configuration.client.execute(req).await?;
80
81    let status = resp.status();
82    let content_type = resp
83        .headers()
84        .get("content-type")
85        .and_then(|v| v.to_str().ok())
86        .unwrap_or("application/octet-stream");
87    let content_type = super::ContentType::from(content_type);
88
89    if !status.is_client_error() && !status.is_server_error() {
90        let content = resp.text().await?;
91        match content_type {
92            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
93            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AlterTransactionResponse`"))),
94            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::AlterTransactionResponse`")))),
95        }
96    } else {
97        let content = resp.text().await?;
98        let entity: Option<AlterTransactionError> = serde_json::from_str(&content).ok();
99        Err(Error::ResponseError(ResponseContent { status, content, entity }))
100    }
101}
102
103/// Return a detailed information for a given transaction 
104pub async fn describe_transaction(configuration: &configuration::Configuration, id: &str, describe_transaction_request: models::DescribeTransactionRequest, delimiter: Option<&str>) -> Result<models::DescribeTransactionResponse, Error<DescribeTransactionError>> {
105    // add a prefix to parameters to efficiently prevent name collisions
106    let p_id = id;
107    let p_describe_transaction_request = describe_transaction_request;
108    let p_delimiter = delimiter;
109
110    let uri_str = format!("{}/v1/transaction/{id}/describe", configuration.base_path, id=crate::apis::urlencode(p_id));
111    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
112
113    if let Some(ref param_value) = p_delimiter {
114        req_builder = req_builder.query(&[("delimiter", &param_value.to_string())]);
115    }
116    if let Some(ref user_agent) = configuration.user_agent {
117        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
118    }
119    if let Some(ref token) = configuration.oauth_access_token {
120        req_builder = req_builder.bearer_auth(token.to_owned());
121    };
122    if let Some(ref apikey) = configuration.api_key {
123        let key = apikey.key.clone();
124        let value = match apikey.prefix {
125            Some(ref prefix) => format!("{} {}", prefix, key),
126            None => key,
127        };
128        req_builder = req_builder.header("x-api-key", value);
129    };
130    if let Some(ref token) = configuration.bearer_access_token {
131        req_builder = req_builder.bearer_auth(token.to_owned());
132    };
133    req_builder = req_builder.json(&p_describe_transaction_request);
134
135    let req = req_builder.build()?;
136    let resp = configuration.client.execute(req).await?;
137
138    let status = resp.status();
139    let content_type = resp
140        .headers()
141        .get("content-type")
142        .and_then(|v| v.to_str().ok())
143        .unwrap_or("application/octet-stream");
144    let content_type = super::ContentType::from(content_type);
145
146    if !status.is_client_error() && !status.is_server_error() {
147        let content = resp.text().await?;
148        match content_type {
149            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
150            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DescribeTransactionResponse`"))),
151            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::DescribeTransactionResponse`")))),
152        }
153    } else {
154        let content = resp.text().await?;
155        let entity: Option<DescribeTransactionError> = serde_json::from_str(&content).ok();
156        Err(Error::ResponseError(ResponseContent { status, content, entity }))
157    }
158}
159