zsgf_client/apis/
user_setting_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 [`user_setting`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum UserSettingError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`user_setting_delete`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum UserSettingDeleteError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`user_setting_post`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum UserSettingPostError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`user_setting_put`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum UserSettingPutError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`user_settings`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum UserSettingsError {
50    UnknownValue(serde_json::Value),
51}
52
53
54/// 根据配置项ID获取用户配置项详情
55pub async fn user_setting(configuration: &configuration::Configuration, id: i64, app_key: &str) -> Result<models::UserSettingApiResponse, Error<UserSettingError>> {
56    // add a prefix to parameters to efficiently prevent name collisions
57    let p_id = id;
58    let p_app_key = app_key;
59
60    let uri_str = format!("{}/UserSetting/{appKey}/{id}", configuration.base_path, id=p_id, appKey=crate::apis::urlencode(p_app_key));
61    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
62
63    if let Some(ref user_agent) = configuration.user_agent {
64        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
65    }
66    if let Some(ref token) = configuration.bearer_access_token {
67        req_builder = req_builder.bearer_auth(token.to_owned());
68    };
69
70    let req = req_builder.build()?;
71    let resp = configuration.client.execute(req).await?;
72
73    let status = resp.status();
74    let content_type = resp
75        .headers()
76        .get("content-type")
77        .and_then(|v| v.to_str().ok())
78        .unwrap_or("application/octet-stream");
79    let content_type = super::ContentType::from(content_type);
80
81    if !status.is_client_error() && !status.is_server_error() {
82        let content = resp.text().await?;
83        match content_type {
84            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
85            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserSettingApiResponse`"))),
86            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::UserSettingApiResponse`")))),
87        }
88    } else {
89        let content = resp.text().await?;
90        let entity: Option<UserSettingError> = serde_json::from_str(&content).ok();
91        Err(Error::ResponseError(ResponseContent { status, content, entity }))
92    }
93}
94
95/// 根据配置项ID删除用户配置项
96pub async fn user_setting_delete(configuration: &configuration::Configuration, id: i64, app_key: &str) -> Result<models::BooleanApiResponse, Error<UserSettingDeleteError>> {
97    // add a prefix to parameters to efficiently prevent name collisions
98    let p_id = id;
99    let p_app_key = app_key;
100
101    let uri_str = format!("{}/UserSetting/{appKey}/{id}", configuration.base_path, id=p_id, appKey=crate::apis::urlencode(p_app_key));
102    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
103
104    if let Some(ref user_agent) = configuration.user_agent {
105        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
106    }
107    if let Some(ref token) = configuration.bearer_access_token {
108        req_builder = req_builder.bearer_auth(token.to_owned());
109    };
110
111    let req = req_builder.build()?;
112    let resp = configuration.client.execute(req).await?;
113
114    let status = resp.status();
115    let content_type = resp
116        .headers()
117        .get("content-type")
118        .and_then(|v| v.to_str().ok())
119        .unwrap_or("application/octet-stream");
120    let content_type = super::ContentType::from(content_type);
121
122    if !status.is_client_error() && !status.is_server_error() {
123        let content = resp.text().await?;
124        match content_type {
125            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
126            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BooleanApiResponse`"))),
127            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::BooleanApiResponse`")))),
128        }
129    } else {
130        let content = resp.text().await?;
131        let entity: Option<UserSettingDeleteError> = serde_json::from_str(&content).ok();
132        Err(Error::ResponseError(ResponseContent { status, content, entity }))
133    }
134}
135
136/// 添加新的用户配置项
137pub async fn user_setting_post(configuration: &configuration::Configuration, app_key: &str, user_setting: Option<models::UserSetting>) -> Result<models::UserSettingPostResultApiResponse, Error<UserSettingPostError>> {
138    // add a prefix to parameters to efficiently prevent name collisions
139    let p_app_key = app_key;
140    let p_user_setting = user_setting;
141
142    let uri_str = format!("{}/UserSetting/{appKey}", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
143    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
144
145    if let Some(ref user_agent) = configuration.user_agent {
146        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
147    }
148    if let Some(ref token) = configuration.bearer_access_token {
149        req_builder = req_builder.bearer_auth(token.to_owned());
150    };
151    req_builder = req_builder.json(&p_user_setting);
152
153    let req = req_builder.build()?;
154    let resp = configuration.client.execute(req).await?;
155
156    let status = resp.status();
157    let content_type = resp
158        .headers()
159        .get("content-type")
160        .and_then(|v| v.to_str().ok())
161        .unwrap_or("application/octet-stream");
162    let content_type = super::ContentType::from(content_type);
163
164    if !status.is_client_error() && !status.is_server_error() {
165        let content = resp.text().await?;
166        match content_type {
167            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
168            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserSettingPostResultApiResponse`"))),
169            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::UserSettingPostResultApiResponse`")))),
170        }
171    } else {
172        let content = resp.text().await?;
173        let entity: Option<UserSettingPostError> = serde_json::from_str(&content).ok();
174        Err(Error::ResponseError(ResponseContent { status, content, entity }))
175    }
176}
177
178/// 根据配置项ID更新用户配置项内容
179pub async fn user_setting_put(configuration: &configuration::Configuration, id: i64, app_key: &str, user_setting: Option<models::UserSetting>) -> Result<models::BooleanApiResponse, Error<UserSettingPutError>> {
180    // add a prefix to parameters to efficiently prevent name collisions
181    let p_id = id;
182    let p_app_key = app_key;
183    let p_user_setting = user_setting;
184
185    let uri_str = format!("{}/UserSetting/{appKey}/{id}", configuration.base_path, id=p_id, appKey=crate::apis::urlencode(p_app_key));
186    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
187
188    if let Some(ref user_agent) = configuration.user_agent {
189        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
190    }
191    if let Some(ref token) = configuration.bearer_access_token {
192        req_builder = req_builder.bearer_auth(token.to_owned());
193    };
194    req_builder = req_builder.json(&p_user_setting);
195
196    let req = req_builder.build()?;
197    let resp = configuration.client.execute(req).await?;
198
199    let status = resp.status();
200    let content_type = resp
201        .headers()
202        .get("content-type")
203        .and_then(|v| v.to_str().ok())
204        .unwrap_or("application/octet-stream");
205    let content_type = super::ContentType::from(content_type);
206
207    if !status.is_client_error() && !status.is_server_error() {
208        let content = resp.text().await?;
209        match content_type {
210            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
211            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BooleanApiResponse`"))),
212            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::BooleanApiResponse`")))),
213        }
214    } else {
215        let content = resp.text().await?;
216        let entity: Option<UserSettingPutError> = serde_json::from_str(&content).ok();
217        Err(Error::ResponseError(ResponseContent { status, content, entity }))
218    }
219}
220
221/// 根据用户ID、配置项代码和标签获取用户配置列表
222pub async fn user_settings(configuration: &configuration::Configuration, app_key: &str, user_id: Option<i64>, code: Option<&str>, tag: Option<&str>) -> Result<models::UserSettingListApiResponse, Error<UserSettingsError>> {
223    // add a prefix to parameters to efficiently prevent name collisions
224    let p_app_key = app_key;
225    let p_user_id = user_id;
226    let p_code = code;
227    let p_tag = tag;
228
229    let uri_str = format!("{}/UserSetting/{appKey}", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
230    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
231
232    if let Some(ref param_value) = p_user_id {
233        req_builder = req_builder.query(&[("userId", &param_value.to_string())]);
234    }
235    if let Some(ref param_value) = p_code {
236        req_builder = req_builder.query(&[("code", &param_value.to_string())]);
237    }
238    if let Some(ref param_value) = p_tag {
239        req_builder = req_builder.query(&[("tag", &param_value.to_string())]);
240    }
241    if let Some(ref user_agent) = configuration.user_agent {
242        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
243    }
244    if let Some(ref token) = configuration.bearer_access_token {
245        req_builder = req_builder.bearer_auth(token.to_owned());
246    };
247
248    let req = req_builder.build()?;
249    let resp = configuration.client.execute(req).await?;
250
251    let status = resp.status();
252    let content_type = resp
253        .headers()
254        .get("content-type")
255        .and_then(|v| v.to_str().ok())
256        .unwrap_or("application/octet-stream");
257    let content_type = super::ContentType::from(content_type);
258
259    if !status.is_client_error() && !status.is_server_error() {
260        let content = resp.text().await?;
261        match content_type {
262            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
263            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserSettingListApiResponse`"))),
264            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::UserSettingListApiResponse`")))),
265        }
266    } else {
267        let content = resp.text().await?;
268        let entity: Option<UserSettingsError> = serde_json::from_str(&content).ok();
269        Err(Error::ResponseError(ResponseContent { status, content, entity }))
270    }
271}
272