dynamo_async_openai/
users.rs1use serde::Serialize;
12
13use crate::{
14 Client,
15 config::Config,
16 error::OpenAIError,
17 types::{User, UserDeleteResponse, UserListResponse, UserRoleUpdateRequest},
18};
19
20pub struct Users<'c, C: Config> {
22 client: &'c Client<C>,
23}
24
25impl<'c, C: Config> Users<'c, C> {
26 pub fn new(client: &'c Client<C>) -> Self {
27 Self { client }
28 }
29
30 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
32 pub async fn list<Q>(&self, query: &Q) -> Result<UserListResponse, OpenAIError>
33 where
34 Q: Serialize + ?Sized,
35 {
36 self.client
37 .get_with_query("/organization/users", &query)
38 .await
39 }
40
41 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
43 pub async fn modify(
44 &self,
45 user_id: &str,
46 request: UserRoleUpdateRequest,
47 ) -> Result<User, OpenAIError> {
48 self.client
49 .post(format!("/organization/users/{user_id}").as_str(), request)
50 .await
51 }
52
53 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
55 pub async fn retrieve(&self, user_id: &str) -> Result<User, OpenAIError> {
56 self.client
57 .get(format!("/organization/users/{user_id}").as_str())
58 .await
59 }
60
61 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
63 pub async fn delete(&self, user_id: &str) -> Result<UserDeleteResponse, OpenAIError> {
64 self.client
65 .delete(format!("/organizations/users/{user_id}").as_str())
66 .await
67 }
68}