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 CreateProjectMemberParams {
20 pub project_name_or_id: String,
22 pub x_request_id: Option<String>,
24 pub x_is_resource_name: Option<bool>,
26 pub project_member: Option<models::ProjectMember>
27}
28
29#[derive(Clone, Debug)]
31pub struct DeleteProjectMemberParams {
32 pub project_name_or_id: String,
34 pub mid: i64,
36 pub x_request_id: Option<String>,
38 pub x_is_resource_name: Option<bool>
40}
41
42#[derive(Clone, Debug)]
44pub struct GetProjectMemberParams {
45 pub project_name_or_id: String,
47 pub mid: i64,
49 pub x_request_id: Option<String>,
51 pub x_is_resource_name: Option<bool>
53}
54
55#[derive(Clone, Debug)]
57pub struct ListProjectMembersParams {
58 pub project_name_or_id: String,
60 pub x_request_id: Option<String>,
62 pub x_is_resource_name: Option<bool>,
64 pub page: Option<i64>,
66 pub page_size: Option<i64>,
68 pub entityname: Option<String>
70}
71
72#[derive(Clone, Debug)]
74pub struct UpdateProjectMemberParams {
75 pub project_name_or_id: String,
77 pub mid: i64,
79 pub x_request_id: Option<String>,
81 pub x_is_resource_name: Option<bool>,
83 pub role: Option<models::RoleRequest>
84}
85
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum CreateProjectMemberError {
91 Status400(models::Errors),
92 Status401(models::Errors),
93 Status403(models::Errors),
94 Status409(models::Errors),
95 Status500(models::Errors),
96 UnknownValue(serde_json::Value),
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum DeleteProjectMemberError {
103 Status400(models::Errors),
104 Status401(models::Errors),
105 Status403(models::Errors),
106 Status500(models::Errors),
107 UnknownValue(serde_json::Value),
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(untagged)]
113pub enum GetProjectMemberError {
114 Status400(models::Errors),
115 Status401(models::Errors),
116 Status403(models::Errors),
117 Status404(models::Errors),
118 Status500(models::Errors),
119 UnknownValue(serde_json::Value),
120}
121
122#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum ListProjectMembersError {
126 Status400(models::Errors),
127 Status401(models::Errors),
128 Status403(models::Errors),
129 Status404(models::Errors),
130 Status500(models::Errors),
131 UnknownValue(serde_json::Value),
132}
133
134#[derive(Debug, Clone, Serialize, Deserialize)]
136#[serde(untagged)]
137pub enum UpdateProjectMemberError {
138 Status400(models::Errors),
139 Status401(models::Errors),
140 Status403(models::Errors),
141 Status404(models::Errors),
142 Status500(models::Errors),
143 UnknownValue(serde_json::Value),
144}
145
146
147pub async fn create_project_member(configuration: &configuration::Configuration, params: CreateProjectMemberParams) -> Result<(), Error<CreateProjectMemberError>> {
149
150 let uri_str = format!("{}/projects/{project_name_or_id}/members", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
151 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
152
153 if let Some(ref user_agent) = configuration.user_agent {
154 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
155 }
156 if let Some(param_value) = params.x_request_id {
157 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
158 }
159 if let Some(param_value) = params.x_is_resource_name {
160 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
161 }
162 if let Some(ref auth_conf) = configuration.basic_auth {
163 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
164 };
165 req_builder = req_builder.json(¶ms.project_member);
166
167 let req = req_builder.build()?;
168 let resp = configuration.client.execute(req).await?;
169
170 let status = resp.status();
171
172 if !status.is_client_error() && !status.is_server_error() {
173 Ok(())
174 } else {
175 let content = resp.text().await?;
176 let entity: Option<CreateProjectMemberError> = serde_json::from_str(&content).ok();
177 Err(Error::ResponseError(ResponseContent { status, content, entity }))
178 }
179}
180
181pub async fn delete_project_member(configuration: &configuration::Configuration, params: DeleteProjectMemberParams) -> Result<(), Error<DeleteProjectMemberError>> {
182
183 let uri_str = format!("{}/projects/{project_name_or_id}/members/{mid}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), mid=params.mid);
184 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
185
186 if let Some(ref user_agent) = configuration.user_agent {
187 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
188 }
189 if let Some(param_value) = params.x_request_id {
190 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
191 }
192 if let Some(param_value) = params.x_is_resource_name {
193 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
194 }
195 if let Some(ref auth_conf) = configuration.basic_auth {
196 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
197 };
198
199 let req = req_builder.build()?;
200 let resp = configuration.client.execute(req).await?;
201
202 let status = resp.status();
203
204 if !status.is_client_error() && !status.is_server_error() {
205 Ok(())
206 } else {
207 let content = resp.text().await?;
208 let entity: Option<DeleteProjectMemberError> = serde_json::from_str(&content).ok();
209 Err(Error::ResponseError(ResponseContent { status, content, entity }))
210 }
211}
212
213pub async fn get_project_member(configuration: &configuration::Configuration, params: GetProjectMemberParams) -> Result<models::ProjectMemberEntity, Error<GetProjectMemberError>> {
215
216 let uri_str = format!("{}/projects/{project_name_or_id}/members/{mid}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), mid=params.mid);
217 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
218
219 if let Some(ref user_agent) = configuration.user_agent {
220 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
221 }
222 if let Some(param_value) = params.x_request_id {
223 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
224 }
225 if let Some(param_value) = params.x_is_resource_name {
226 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
227 }
228 if let Some(ref auth_conf) = configuration.basic_auth {
229 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
230 };
231
232 let req = req_builder.build()?;
233 let resp = configuration.client.execute(req).await?;
234
235 let status = resp.status();
236 let content_type = resp
237 .headers()
238 .get("content-type")
239 .and_then(|v| v.to_str().ok())
240 .unwrap_or("application/octet-stream");
241 let content_type = super::ContentType::from(content_type);
242
243 if !status.is_client_error() && !status.is_server_error() {
244 let content = resp.text().await?;
245 match content_type {
246 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
247 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProjectMemberEntity`"))),
248 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::ProjectMemberEntity`")))),
249 }
250 } else {
251 let content = resp.text().await?;
252 let entity: Option<GetProjectMemberError> = serde_json::from_str(&content).ok();
253 Err(Error::ResponseError(ResponseContent { status, content, entity }))
254 }
255}
256
257pub async fn list_project_members(configuration: &configuration::Configuration, params: ListProjectMembersParams) -> Result<Vec<models::ProjectMemberEntity>, Error<ListProjectMembersError>> {
259
260 let uri_str = format!("{}/projects/{project_name_or_id}/members", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id));
261 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
262
263 if let Some(ref param_value) = params.page {
264 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
265 }
266 if let Some(ref param_value) = params.page_size {
267 req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
268 }
269 if let Some(ref param_value) = params.entityname {
270 req_builder = req_builder.query(&[("entityname", ¶m_value.to_string())]);
271 }
272 if let Some(ref user_agent) = configuration.user_agent {
273 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
274 }
275 if let Some(param_value) = params.x_request_id {
276 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
277 }
278 if let Some(param_value) = params.x_is_resource_name {
279 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
280 }
281 if let Some(ref auth_conf) = configuration.basic_auth {
282 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
283 };
284
285 let req = req_builder.build()?;
286 let resp = configuration.client.execute(req).await?;
287
288 let status = resp.status();
289 let content_type = resp
290 .headers()
291 .get("content-type")
292 .and_then(|v| v.to_str().ok())
293 .unwrap_or("application/octet-stream");
294 let content_type = super::ContentType::from(content_type);
295
296 if !status.is_client_error() && !status.is_server_error() {
297 let content = resp.text().await?;
298 match content_type {
299 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
300 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::ProjectMemberEntity>`"))),
301 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::ProjectMemberEntity>`")))),
302 }
303 } else {
304 let content = resp.text().await?;
305 let entity: Option<ListProjectMembersError> = serde_json::from_str(&content).ok();
306 Err(Error::ResponseError(ResponseContent { status, content, entity }))
307 }
308}
309
310pub async fn update_project_member(configuration: &configuration::Configuration, params: UpdateProjectMemberParams) -> Result<(), Error<UpdateProjectMemberError>> {
312
313 let uri_str = format!("{}/projects/{project_name_or_id}/members/{mid}", configuration.base_path, project_name_or_id=crate::apis::urlencode(params.project_name_or_id), mid=params.mid);
314 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
315
316 if let Some(ref user_agent) = configuration.user_agent {
317 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
318 }
319 if let Some(param_value) = params.x_request_id {
320 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
321 }
322 if let Some(param_value) = params.x_is_resource_name {
323 req_builder = req_builder.header("X-Is-Resource-Name", param_value.to_string());
324 }
325 if let Some(ref auth_conf) = configuration.basic_auth {
326 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
327 };
328 req_builder = req_builder.json(¶ms.role);
329
330 let req = req_builder.build()?;
331 let resp = configuration.client.execute(req).await?;
332
333 let status = resp.status();
334
335 if !status.is_client_error() && !status.is_server_error() {
336 Ok(())
337 } else {
338 let content = resp.text().await?;
339 let entity: Option<UpdateProjectMemberError> = serde_json::from_str(&content).ok();
340 Err(Error::ResponseError(ResponseContent { status, content, entity }))
341 }
342}
343