use std::sync::Arc;
use async_trait::async_trait;
#[cfg(feature = "mockall")]
use mockall::automock;
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use super::{Error, configuration};
use crate::{
apis::{AuthRequired, ContentType, ResponseContent},
models,
};
#[cfg_attr(feature = "mockall", automock)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait ProjectsApi: Send + Sync {
async fn bulk_delete<'a>(
&self,
uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
) -> Result<models::BulkDeleteResponseModelListResponseModel, Error>;
async fn create<'a>(
&self,
organization_id: uuid::Uuid,
project_create_request_model: Option<models::ProjectCreateRequestModel>,
) -> Result<models::ProjectResponseModel, Error>;
async fn get<'a>(&self, id: uuid::Uuid) -> Result<models::ProjectResponseModel, Error>;
async fn list_by_organization<'a>(
&self,
organization_id: uuid::Uuid,
) -> Result<models::ProjectResponseModelListResponseModel, Error>;
async fn update<'a>(
&self,
id: uuid::Uuid,
project_update_request_model: Option<models::ProjectUpdateRequestModel>,
) -> Result<models::ProjectResponseModel, Error>;
}
pub struct ProjectsApiClient {
configuration: Arc<configuration::Configuration>,
}
impl ProjectsApiClient {
pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
Self { configuration }
}
}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl ProjectsApi for ProjectsApiClient {
async fn bulk_delete<'a>(
&self,
uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
) -> Result<models::BulkDeleteResponseModelListResponseModel, Error> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/projects/delete", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
bitwarden_api_base::process_with_json_response(local_var_req_builder).await
}
async fn create<'a>(
&self,
organization_id: uuid::Uuid,
project_create_request_model: Option<models::ProjectCreateRequestModel>,
) -> Result<models::ProjectResponseModel, Error> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/organizations/{organizationId}/projects",
local_var_configuration.base_path,
organizationId = organization_id
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
local_var_req_builder = local_var_req_builder.json(&project_create_request_model);
bitwarden_api_base::process_with_json_response(local_var_req_builder).await
}
async fn get<'a>(&self, id: uuid::Uuid) -> Result<models::ProjectResponseModel, Error> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/projects/{id}",
local_var_configuration.base_path,
id = id
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
bitwarden_api_base::process_with_json_response(local_var_req_builder).await
}
async fn list_by_organization<'a>(
&self,
organization_id: uuid::Uuid,
) -> Result<models::ProjectResponseModelListResponseModel, Error> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/organizations/{organizationId}/projects",
local_var_configuration.base_path,
organizationId = organization_id
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
bitwarden_api_base::process_with_json_response(local_var_req_builder).await
}
async fn update<'a>(
&self,
id: uuid::Uuid,
project_update_request_model: Option<models::ProjectUpdateRequestModel>,
) -> Result<models::ProjectResponseModel, Error> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/projects/{id}",
local_var_configuration.base_path,
id = id
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
local_var_req_builder = local_var_req_builder.json(&project_update_request_model);
bitwarden_api_base::process_with_json_response(local_var_req_builder).await
}
}