zsgf_client/apis/
order_api.rs

1/*
2 * 全部  API 文档
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: v1
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 [`order`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum OrderError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`order_create`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum OrderCreateError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`orders`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum OrdersError {
36    UnknownValue(serde_json::Value),
37}
38
39
40/// 根据订单ID获取订单详情
41pub async fn order(configuration: &configuration::Configuration, id: i64, app_key: &str) -> Result<models::OrderApiResponse, Error<OrderError>> {
42    // add a prefix to parameters to efficiently prevent name collisions
43    let p_id = id;
44    let p_app_key = app_key;
45
46    let uri_str = format!("{}/Order/{appKey}/{id}", configuration.base_path, id=p_id, appKey=crate::apis::urlencode(p_app_key));
47    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
48
49    if let Some(ref user_agent) = configuration.user_agent {
50        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
51    }
52    if let Some(ref token) = configuration.bearer_access_token {
53        req_builder = req_builder.bearer_auth(token.to_owned());
54    };
55
56    let req = req_builder.build()?;
57    let resp = configuration.client.execute(req).await?;
58
59    let status = resp.status();
60    let content_type = resp
61        .headers()
62        .get("content-type")
63        .and_then(|v| v.to_str().ok())
64        .unwrap_or("application/octet-stream");
65    let content_type = super::ContentType::from(content_type);
66
67    if !status.is_client_error() && !status.is_server_error() {
68        let content = resp.text().await?;
69        match content_type {
70            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
71            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OrderApiResponse`"))),
72            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::OrderApiResponse`")))),
73        }
74    } else {
75        let content = resp.text().await?;
76        let entity: Option<OrderError> = serde_json::from_str(&content).ok();
77        Err(Error::ResponseError(ResponseContent { status, content, entity }))
78    }
79}
80
81/// 根据请求参数创建订单
82pub async fn order_create(configuration: &configuration::Configuration, app_key: &str, create_order_request: Option<models::CreateOrderRequest>) -> Result<models::CreateOrderResultApiResponse, Error<OrderCreateError>> {
83    // add a prefix to parameters to efficiently prevent name collisions
84    let p_app_key = app_key;
85    let p_create_order_request = create_order_request;
86
87    let uri_str = format!("{}/Order/{appKey}/Create", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
88    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
89
90    if let Some(ref user_agent) = configuration.user_agent {
91        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
92    }
93    if let Some(ref token) = configuration.bearer_access_token {
94        req_builder = req_builder.bearer_auth(token.to_owned());
95    };
96    req_builder = req_builder.json(&p_create_order_request);
97
98    let req = req_builder.build()?;
99    let resp = configuration.client.execute(req).await?;
100
101    let status = resp.status();
102    let content_type = resp
103        .headers()
104        .get("content-type")
105        .and_then(|v| v.to_str().ok())
106        .unwrap_or("application/octet-stream");
107    let content_type = super::ContentType::from(content_type);
108
109    if !status.is_client_error() && !status.is_server_error() {
110        let content = resp.text().await?;
111        match content_type {
112            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
113            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateOrderResultApiResponse`"))),
114            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::CreateOrderResultApiResponse`")))),
115        }
116    } else {
117        let content = resp.text().await?;
118        let entity: Option<OrderCreateError> = serde_json::from_str(&content).ok();
119        Err(Error::ResponseError(ResponseContent { status, content, entity }))
120    }
121}
122
123/// 根据查询条件获取订单列表
124pub async fn orders(configuration: &configuration::Configuration, app_key: &str, status: Option<&str>, order_no: Option<&str>, trade_no: Option<&str>, user_id: Option<i64>, pct_type: Option<&str>, pct_id: Option<&str>, pct_name: Option<&str>, skip: Option<i32>, take: Option<i32>) -> Result<models::OrderListResultApiResponse, Error<OrdersError>> {
125    // add a prefix to parameters to efficiently prevent name collisions
126    let p_app_key = app_key;
127    let p_status = status;
128    let p_order_no = order_no;
129    let p_trade_no = trade_no;
130    let p_user_id = user_id;
131    let p_pct_type = pct_type;
132    let p_pct_id = pct_id;
133    let p_pct_name = pct_name;
134    let p_skip = skip;
135    let p_take = take;
136
137    let uri_str = format!("{}/Order/{appKey}", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
138    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
139
140    if let Some(ref param_value) = p_status {
141        req_builder = req_builder.query(&[("status", &param_value.to_string())]);
142    }
143    if let Some(ref param_value) = p_order_no {
144        req_builder = req_builder.query(&[("orderNo", &param_value.to_string())]);
145    }
146    if let Some(ref param_value) = p_trade_no {
147        req_builder = req_builder.query(&[("tradeNo", &param_value.to_string())]);
148    }
149    if let Some(ref param_value) = p_user_id {
150        req_builder = req_builder.query(&[("userId", &param_value.to_string())]);
151    }
152    if let Some(ref param_value) = p_pct_type {
153        req_builder = req_builder.query(&[("pctType", &param_value.to_string())]);
154    }
155    if let Some(ref param_value) = p_pct_id {
156        req_builder = req_builder.query(&[("pctId", &param_value.to_string())]);
157    }
158    if let Some(ref param_value) = p_pct_name {
159        req_builder = req_builder.query(&[("pctName", &param_value.to_string())]);
160    }
161    if let Some(ref param_value) = p_skip {
162        req_builder = req_builder.query(&[("skip", &param_value.to_string())]);
163    }
164    if let Some(ref param_value) = p_take {
165        req_builder = req_builder.query(&[("take", &param_value.to_string())]);
166    }
167    if let Some(ref user_agent) = configuration.user_agent {
168        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
169    }
170    if let Some(ref token) = configuration.bearer_access_token {
171        req_builder = req_builder.bearer_auth(token.to_owned());
172    };
173
174    let req = req_builder.build()?;
175    let resp = configuration.client.execute(req).await?;
176
177    let status = resp.status();
178    let content_type = resp
179        .headers()
180        .get("content-type")
181        .and_then(|v| v.to_str().ok())
182        .unwrap_or("application/octet-stream");
183    let content_type = super::ContentType::from(content_type);
184
185    if !status.is_client_error() && !status.is_server_error() {
186        let content = resp.text().await?;
187        match content_type {
188            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
189            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OrderListResultApiResponse`"))),
190            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::OrderListResultApiResponse`")))),
191        }
192    } else {
193        let content = resp.text().await?;
194        let entity: Option<OrdersError> = serde_json::from_str(&content).ok();
195        Err(Error::ResponseError(ResponseContent { status, content, entity }))
196    }
197}
198