|
1 |
| -use crate::prelude::*; |
2 |
| -use azure_core::Request as HttpRequest; |
| 1 | +use crate::{prelude::*, resources::user::UserResponse}; |
| 2 | +use azure_core::Context; |
3 | 3 |
|
4 |
| -#[derive(Debug, Clone, Default)] |
5 |
| -pub struct CreateUserOptions { |
| 4 | +#[derive(Debug, Clone)] |
| 5 | +pub struct CreateUserBuilder { |
| 6 | + client: UserClient, |
6 | 7 | consistency_level: Option<ConsistencyLevel>,
|
| 8 | + context: Context, |
7 | 9 | }
|
8 | 10 |
|
9 |
| -impl CreateUserOptions { |
10 |
| - pub fn new() -> Self { |
| 11 | +impl CreateUserBuilder { |
| 12 | + pub(crate) fn new(client: UserClient) -> Self { |
11 | 13 | Self {
|
| 14 | + client, |
12 | 15 | consistency_level: None,
|
| 16 | + context: Context::new(), |
13 | 17 | }
|
14 | 18 | }
|
15 | 19 |
|
16 | 20 | setters! {
|
17 | 21 | consistency_level: ConsistencyLevel => Some(consistency_level),
|
18 | 22 | }
|
19 | 23 |
|
20 |
| - pub(crate) fn decorate_request( |
21 |
| - &self, |
22 |
| - request: &mut HttpRequest, |
23 |
| - user_name: &str, |
24 |
| - ) -> crate::Result<()> { |
25 |
| - azure_core::headers::add_optional_header2(&self.consistency_level, request)?; |
26 |
| - let body = CreateUserBody { id: user_name }; |
27 |
| - request.set_body(bytes::Bytes::from(serde_json::to_string(&body)?).into()); |
28 |
| - Ok(()) |
| 24 | + pub fn into_future(self) -> CreateUser { |
| 25 | + Box::pin(async move { |
| 26 | + let mut request = self.client.cosmos_client().prepare_request_pipeline( |
| 27 | + &format!( |
| 28 | + "dbs/{}/users", |
| 29 | + self.client.database_client().database_name() |
| 30 | + ), |
| 31 | + http::Method::POST, |
| 32 | + ); |
| 33 | + |
| 34 | + azure_core::headers::add_optional_header2(&self.consistency_level, &mut request)?; |
| 35 | + let body = CreateUserBody { |
| 36 | + id: self.client.user_name(), |
| 37 | + }; |
| 38 | + request.set_body(bytes::Bytes::from(serde_json::to_string(&body)?).into()); |
| 39 | + let response = self |
| 40 | + .client |
| 41 | + .pipeline() |
| 42 | + .send( |
| 43 | + self.context.clone().insert(ResourceType::Users), |
| 44 | + &mut request, |
| 45 | + ) |
| 46 | + .await?; |
| 47 | + |
| 48 | + Ok(UserResponse::try_from(response).await?) |
| 49 | + }) |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +type CreateUser = futures::future::BoxFuture<'static, crate::Result<UserResponse>>; |
| 54 | + |
| 55 | +#[cfg(feature = "into_future")] |
| 56 | +impl std::future::IntoFuture for CreateUserBuilder { |
| 57 | + type Future = CreateUser; |
| 58 | + type Output = <CreateUser as std::future::Future>::Output; |
| 59 | + fn into_future(self) -> Self::Future { |
| 60 | + Self::into_future(self) |
29 | 61 | }
|
30 | 62 | }
|
31 | 63 |
|
|
0 commit comments