1use serde::Serialize;
2
3use crate::{
4 config::Config,
5 error::OpenAIError,
6 project_api_keys::ProjectAPIKeys,
7 types::{Project, ProjectCreateRequest, ProjectListResponse, ProjectUpdateRequest},
8 Client, ProjectServiceAccounts, ProjectUsers,
9};
10
11pub struct Projects<'c, C: Config> {
14 client: &'c Client<C>,
15}
16
17impl<'c, C: Config> Projects<'c, C> {
18 pub fn new(client: &'c Client<C>) -> Self {
19 Self { client }
20 }
21
22 pub fn users(&self, project_id: &str) -> ProjectUsers<C> {
24 ProjectUsers::new(self.client, project_id)
25 }
26
27 pub fn service_accounts(&self, project_id: &str) -> ProjectServiceAccounts<C> {
29 ProjectServiceAccounts::new(self.client, project_id)
30 }
31
32 pub fn api_keys(&self, project_id: &str) -> ProjectAPIKeys<C> {
34 ProjectAPIKeys::new(self.client, project_id)
35 }
36
37 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
39 pub async fn list<Q>(&self, query: &Q) -> Result<ProjectListResponse, OpenAIError>
40 where
41 Q: Serialize + ?Sized,
42 {
43 self.client
44 .get_with_query("/organization/projects", &query)
45 .await
46 }
47
48 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
50 pub async fn create(&self, request: ProjectCreateRequest) -> Result<Project, OpenAIError> {
51 self.client.post("/organization/projects", request).await
52 }
53
54 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
56 pub async fn retrieve(&self, project_id: String) -> Result<Project, OpenAIError> {
57 self.client
58 .get(format!("/organization/projects/{project_id}").as_str())
59 .await
60 }
61
62 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
64 pub async fn modify(
65 &self,
66 project_id: String,
67 request: ProjectUpdateRequest,
68 ) -> Result<Project, OpenAIError> {
69 self.client
70 .post(
71 format!("/organization/projects/{project_id}").as_str(),
72 request,
73 )
74 .await
75 }
76
77 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
79 pub async fn archive(&self, project_id: String) -> Result<Project, OpenAIError> {
80 self.client
81 .post(
82 format!("/organization/projects/{project_id}/archive").as_str(),
83 (),
84 )
85 .await
86 }
87}