1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct DeleteRepositoryParams {
20 pub project_name: String,
22 pub repository_name: String,
24 pub x_request_id: Option<String>
26}
27
28#[derive(Clone, Debug)]
30pub struct GetRepositoryParams {
31 pub project_name: String,
33 pub repository_name: String,
35 pub x_request_id: Option<String>
37}
38
39#[derive(Clone, Debug)]
41pub struct ListAllRepositoriesParams {
42 pub x_request_id: Option<String>,
44 pub q: Option<String>,
46 pub sort: Option<String>,
48 pub page: Option<i64>,
50 pub page_size: Option<i64>
52}
53
54#[derive(Clone, Debug)]
56pub struct ListRepositoriesParams {
57 pub project_name: String,
59 pub x_request_id: Option<String>,
61 pub q: Option<String>,
63 pub sort: Option<String>,
65 pub page: Option<i64>,
67 pub page_size: Option<i64>
69}
70
71#[derive(Clone, Debug)]
73pub struct UpdateRepositoryParams {
74 pub project_name: String,
76 pub repository_name: String,
78 pub repository: models::Repository,
80 pub x_request_id: Option<String>
82}
83
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum DeleteRepositoryError {
89 Status400(models::Errors),
90 Status401(models::Errors),
91 Status403(models::Errors),
92 Status404(models::Errors),
93 Status500(models::Errors),
94 UnknownValue(serde_json::Value),
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum GetRepositoryError {
101 Status400(models::Errors),
102 Status401(models::Errors),
103 Status403(models::Errors),
104 Status404(models::Errors),
105 Status500(models::Errors),
106 UnknownValue(serde_json::Value),
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum ListAllRepositoriesError {
113 Status400(models::Errors),
114 Status500(models::Errors),
115 UnknownValue(serde_json::Value),
116}
117
118#[derive(Debug, Clone, Serialize, Deserialize)]
120#[serde(untagged)]
121pub enum ListRepositoriesError {
122 Status400(models::Errors),
123 Status401(models::Errors),
124 Status403(models::Errors),
125 Status404(models::Errors),
126 Status500(models::Errors),
127 UnknownValue(serde_json::Value),
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize)]
132#[serde(untagged)]
133pub enum UpdateRepositoryError {
134 Status400(models::Errors),
135 Status401(models::Errors),
136 Status403(models::Errors),
137 Status404(models::Errors),
138 Status500(models::Errors),
139 UnknownValue(serde_json::Value),
140}
141
142
143pub async fn delete_repository(configuration: &configuration::Configuration, params: DeleteRepositoryParams) -> Result<(), Error<DeleteRepositoryError>> {
145
146 let uri_str = format!("{}/projects/{project_name}/repositories/{repository_name}", configuration.base_path, project_name=crate::apis::urlencode(params.project_name), repository_name=crate::apis::urlencode(params.repository_name));
147 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
148
149 if let Some(ref user_agent) = configuration.user_agent {
150 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
151 }
152 if let Some(param_value) = params.x_request_id {
153 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
154 }
155 if let Some(ref auth_conf) = configuration.basic_auth {
156 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
157 };
158
159 let req = req_builder.build()?;
160 let resp = configuration.client.execute(req).await?;
161
162 let status = resp.status();
163
164 if !status.is_client_error() && !status.is_server_error() {
165 Ok(())
166 } else {
167 let content = resp.text().await?;
168 let entity: Option<DeleteRepositoryError> = serde_json::from_str(&content).ok();
169 Err(Error::ResponseError(ResponseContent { status, content, entity }))
170 }
171}
172
173pub async fn get_repository(configuration: &configuration::Configuration, params: GetRepositoryParams) -> Result<models::Repository, Error<GetRepositoryError>> {
175
176 let uri_str = format!("{}/projects/{project_name}/repositories/{repository_name}", configuration.base_path, project_name=crate::apis::urlencode(params.project_name), repository_name=crate::apis::urlencode(params.repository_name));
177 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
178
179 if let Some(ref user_agent) = configuration.user_agent {
180 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
181 }
182 if let Some(param_value) = params.x_request_id {
183 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
184 }
185 if let Some(ref auth_conf) = configuration.basic_auth {
186 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
187 };
188
189 let req = req_builder.build()?;
190 let resp = configuration.client.execute(req).await?;
191
192 let status = resp.status();
193 let content_type = resp
194 .headers()
195 .get("content-type")
196 .and_then(|v| v.to_str().ok())
197 .unwrap_or("application/octet-stream");
198 let content_type = super::ContentType::from(content_type);
199
200 if !status.is_client_error() && !status.is_server_error() {
201 let content = resp.text().await?;
202 match content_type {
203 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
204 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Repository`"))),
205 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::Repository`")))),
206 }
207 } else {
208 let content = resp.text().await?;
209 let entity: Option<GetRepositoryError> = serde_json::from_str(&content).ok();
210 Err(Error::ResponseError(ResponseContent { status, content, entity }))
211 }
212}
213
214pub async fn list_all_repositories(configuration: &configuration::Configuration, params: ListAllRepositoriesParams) -> Result<Vec<models::Repository>, Error<ListAllRepositoriesError>> {
216
217 let uri_str = format!("{}/repositories", configuration.base_path);
218 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
219
220 if let Some(ref param_value) = params.q {
221 req_builder = req_builder.query(&[("q", ¶m_value.to_string())]);
222 }
223 if let Some(ref param_value) = params.sort {
224 req_builder = req_builder.query(&[("sort", ¶m_value.to_string())]);
225 }
226 if let Some(ref param_value) = params.page {
227 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
228 }
229 if let Some(ref param_value) = params.page_size {
230 req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
231 }
232 if let Some(ref user_agent) = configuration.user_agent {
233 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
234 }
235 if let Some(param_value) = params.x_request_id {
236 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
237 }
238 if let Some(ref auth_conf) = configuration.basic_auth {
239 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
240 };
241
242 let req = req_builder.build()?;
243 let resp = configuration.client.execute(req).await?;
244
245 let status = resp.status();
246 let content_type = resp
247 .headers()
248 .get("content-type")
249 .and_then(|v| v.to_str().ok())
250 .unwrap_or("application/octet-stream");
251 let content_type = super::ContentType::from(content_type);
252
253 if !status.is_client_error() && !status.is_server_error() {
254 let content = resp.text().await?;
255 match content_type {
256 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
257 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Repository>`"))),
258 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Repository>`")))),
259 }
260 } else {
261 let content = resp.text().await?;
262 let entity: Option<ListAllRepositoriesError> = serde_json::from_str(&content).ok();
263 Err(Error::ResponseError(ResponseContent { status, content, entity }))
264 }
265}
266
267pub async fn list_repositories(configuration: &configuration::Configuration, params: ListRepositoriesParams) -> Result<Vec<models::Repository>, Error<ListRepositoriesError>> {
269
270 let uri_str = format!("{}/projects/{project_name}/repositories", configuration.base_path, project_name=crate::apis::urlencode(params.project_name));
271 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
272
273 if let Some(ref param_value) = params.q {
274 req_builder = req_builder.query(&[("q", ¶m_value.to_string())]);
275 }
276 if let Some(ref param_value) = params.sort {
277 req_builder = req_builder.query(&[("sort", ¶m_value.to_string())]);
278 }
279 if let Some(ref param_value) = params.page {
280 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
281 }
282 if let Some(ref param_value) = params.page_size {
283 req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
284 }
285 if let Some(ref user_agent) = configuration.user_agent {
286 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
287 }
288 if let Some(param_value) = params.x_request_id {
289 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
290 }
291 if let Some(ref auth_conf) = configuration.basic_auth {
292 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
293 };
294
295 let req = req_builder.build()?;
296 let resp = configuration.client.execute(req).await?;
297
298 let status = resp.status();
299 let content_type = resp
300 .headers()
301 .get("content-type")
302 .and_then(|v| v.to_str().ok())
303 .unwrap_or("application/octet-stream");
304 let content_type = super::ContentType::from(content_type);
305
306 if !status.is_client_error() && !status.is_server_error() {
307 let content = resp.text().await?;
308 match content_type {
309 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
310 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Repository>`"))),
311 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Repository>`")))),
312 }
313 } else {
314 let content = resp.text().await?;
315 let entity: Option<ListRepositoriesError> = serde_json::from_str(&content).ok();
316 Err(Error::ResponseError(ResponseContent { status, content, entity }))
317 }
318}
319
320pub async fn update_repository(configuration: &configuration::Configuration, params: UpdateRepositoryParams) -> Result<(), Error<UpdateRepositoryError>> {
322
323 let uri_str = format!("{}/projects/{project_name}/repositories/{repository_name}", configuration.base_path, project_name=crate::apis::urlencode(params.project_name), repository_name=crate::apis::urlencode(params.repository_name));
324 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
325
326 if let Some(ref user_agent) = configuration.user_agent {
327 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
328 }
329 if let Some(param_value) = params.x_request_id {
330 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
331 }
332 if let Some(ref auth_conf) = configuration.basic_auth {
333 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
334 };
335 req_builder = req_builder.json(¶ms.repository);
336
337 let req = req_builder.build()?;
338 let resp = configuration.client.execute(req).await?;
339
340 let status = resp.status();
341
342 if !status.is_client_error() && !status.is_server_error() {
343 Ok(())
344 } else {
345 let content = resp.text().await?;
346 let entity: Option<UpdateRepositoryError> = serde_json::from_str(&content).ok();
347 Err(Error::ResponseError(ResponseContent { status, content, entity }))
348 }
349}
350