casdoor_sdk/apis/
model_api.rs

1
2
3use reqwest;
4
5use crate::{apis::ResponseContent, models};
6use super::{Error, configuration};
7
8/// struct for passing parameters to the method [`add_model`]
9#[derive(Clone, Debug)]
10pub struct ApiControllerAddModelParams {
11    /// The details of the model
12    pub body: models::Model
13}
14
15/// struct for passing parameters to the method [`delete_model`]
16#[derive(Clone, Debug)]
17pub struct ApiControllerDeleteModelParams {
18    /// The details of the model
19    pub body: models::Model
20}
21
22/// struct for passing parameters to the method [`get_model`]
23#[derive(Clone, Debug)]
24pub struct ApiControllerGetModelParams {
25    /// The id ( owner/name ) of the model
26    pub id: String
27}
28
29/// struct for passing parameters to the method [`get_models`]
30#[derive(Clone, Debug)]
31pub struct ApiControllerGetModelsParams {
32    /// The owner of models
33    pub owner: String
34}
35
36/// struct for passing parameters to the method [`update_model`]
37#[derive(Clone, Debug)]
38pub struct ApiControllerUpdateModelParams {
39    /// The id ( owner/name ) of the model
40    pub id: String,
41    /// The details of the model
42    pub body: models::Model
43}
44
45
46/// struct for typed errors of method [`add_model`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ApiControllerAddModelError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`delete_model`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum ApiControllerDeleteModelError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`get_model`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ApiControllerGetModelError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`get_models`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ApiControllerGetModelsError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`update_model`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ApiControllerUpdateModelError {
78    UnknownValue(serde_json::Value),
79}
80
81
82/// add model
83pub async fn add_model(configuration: &configuration::Configuration, params: ApiControllerAddModelParams) -> Result<models::ControllersResponse, Error<ApiControllerAddModelError>> {
84    let local_var_configuration = configuration;
85
86    // unbox the parameters
87    let body = params.body;
88
89
90    let local_var_client = &local_var_configuration.client;
91
92    let local_var_uri_str = format!("{}/api/add-model", local_var_configuration.base_path);
93    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
94
95    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
96        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
97    }
98    local_var_req_builder = local_var_req_builder.json(&body);
99
100    let local_var_req = local_var_req_builder.build()?;
101    let local_var_resp = local_var_client.execute(local_var_req).await?;
102
103    let local_var_status = local_var_resp.status();
104    let local_var_content = local_var_resp.text().await?;
105
106    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
107        serde_json::from_str(&local_var_content).map_err(Error::from)
108    } else {
109        let local_var_entity: Option<ApiControllerAddModelError> = serde_json::from_str(&local_var_content).ok();
110        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
111        Err(Error::ResponseError(local_var_error))
112    }
113}
114
115/// delete model
116pub async fn delete_model(configuration: &configuration::Configuration, params: ApiControllerDeleteModelParams) -> Result<models::ControllersResponse, Error<ApiControllerDeleteModelError>> {
117    let local_var_configuration = configuration;
118
119    // unbox the parameters
120    let body = params.body;
121
122
123    let local_var_client = &local_var_configuration.client;
124
125    let local_var_uri_str = format!("{}/api/delete-model", local_var_configuration.base_path);
126    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
127
128    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
129        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
130    }
131    local_var_req_builder = local_var_req_builder.json(&body);
132
133    let local_var_req = local_var_req_builder.build()?;
134    let local_var_resp = local_var_client.execute(local_var_req).await?;
135
136    let local_var_status = local_var_resp.status();
137    let local_var_content = local_var_resp.text().await?;
138
139    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
140        serde_json::from_str(&local_var_content).map_err(Error::from)
141    } else {
142        let local_var_entity: Option<ApiControllerDeleteModelError> = serde_json::from_str(&local_var_content).ok();
143        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
144        Err(Error::ResponseError(local_var_error))
145    }
146}
147
148/// get model
149pub async fn get_model(configuration: &configuration::Configuration, params: ApiControllerGetModelParams) -> Result<models::Model, Error<ApiControllerGetModelError>> {
150    let local_var_configuration = configuration;
151
152    // unbox the parameters
153    let id = params.id;
154
155
156    let local_var_client = &local_var_configuration.client;
157
158    let local_var_uri_str = format!("{}/api/get-model", local_var_configuration.base_path);
159    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
160
161    local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
162    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
163        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
164    }
165
166    let local_var_req = local_var_req_builder.build()?;
167    let local_var_resp = local_var_client.execute(local_var_req).await?;
168
169    let local_var_status = local_var_resp.status();
170    let local_var_content = local_var_resp.text().await?;
171
172    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173        serde_json::from_str(&local_var_content).map_err(Error::from)
174    } else {
175        let local_var_entity: Option<ApiControllerGetModelError> = serde_json::from_str(&local_var_content).ok();
176        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
177        Err(Error::ResponseError(local_var_error))
178    }
179}
180
181/// get models
182pub async fn get_models(configuration: &configuration::Configuration, params: ApiControllerGetModelsParams) -> Result<Vec<models::Model>, Error<ApiControllerGetModelsError>> {
183    let local_var_configuration = configuration;
184
185    // unbox the parameters
186    let owner = params.owner;
187
188
189    let local_var_client = &local_var_configuration.client;
190
191    let local_var_uri_str = format!("{}/api/get-models", local_var_configuration.base_path);
192    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
193
194    local_var_req_builder = local_var_req_builder.query(&[("owner", &owner.to_string())]);
195    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
196        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
197    }
198
199    let local_var_req = local_var_req_builder.build()?;
200    let local_var_resp = local_var_client.execute(local_var_req).await?;
201
202    let local_var_status = local_var_resp.status();
203    let local_var_content = local_var_resp.text().await?;
204
205    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
206        serde_json::from_str(&local_var_content).map_err(Error::from)
207    } else {
208        let local_var_entity: Option<ApiControllerGetModelsError> = serde_json::from_str(&local_var_content).ok();
209        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
210        Err(Error::ResponseError(local_var_error))
211    }
212}
213
214/// update model
215pub async fn update_model(configuration: &configuration::Configuration, params: ApiControllerUpdateModelParams) -> Result<models::ControllersResponse, Error<ApiControllerUpdateModelError>> {
216    let local_var_configuration = configuration;
217
218    // unbox the parameters
219    let id = params.id;
220    let body = params.body;
221
222
223    let local_var_client = &local_var_configuration.client;
224
225    let local_var_uri_str = format!("{}/api/update-model", local_var_configuration.base_path);
226    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
227
228    local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
229    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
230        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
231    }
232    local_var_req_builder = local_var_req_builder.json(&body);
233
234    let local_var_req = local_var_req_builder.build()?;
235    let local_var_resp = local_var_client.execute(local_var_req).await?;
236
237    let local_var_status = local_var_resp.status();
238    let local_var_content = local_var_resp.text().await?;
239
240    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
241        serde_json::from_str(&local_var_content).map_err(Error::from)
242    } else {
243        let local_var_entity: Option<ApiControllerUpdateModelError> = serde_json::from_str(&local_var_content).ok();
244        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
245        Err(Error::ResponseError(local_var_error))
246    }
247}
248