forked from Azure/azure-sdk-for-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move create, get, and replace user to pipeline architecture (Azure#332)
* Move create, get, and replace User to pipeline architecture * Updating e2e tests * fix import Co-authored-by: Joshua Gendein <[email protected]>
- Loading branch information
1 parent
08090ef
commit 356d508
Showing
18 changed files
with
313 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::headers::from_headers::*; | ||
use crate::prelude::*; | ||
use azure_core::{ | ||
collect_pinned_stream, | ||
headers::{etag_from_headers, session_token_from_headers}, | ||
Request as HttpRequest, Response as HttpResponse, | ||
}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct CreateUserOptions { | ||
consistency_level: Option<ConsistencyLevel>, | ||
} | ||
|
||
impl CreateUserOptions { | ||
pub fn new() -> Self { | ||
Self { | ||
consistency_level: None, | ||
} | ||
} | ||
|
||
setters! { | ||
consistency_level: ConsistencyLevel => Some(consistency_level), | ||
} | ||
|
||
pub(crate) fn decorate_request( | ||
&self, | ||
request: &mut HttpRequest, | ||
user_name: &str, | ||
) -> Result<(), crate::Error> { | ||
azure_core::headers::add_optional_header2(&self.consistency_level, request)?; | ||
let body = CreateUserBody { id: user_name }; | ||
request.set_body(bytes::Bytes::from(serde_json::to_string(&body)?).into()); | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Serialize, Debug)] | ||
struct CreateUserBody<'a> { | ||
id: &'a str, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct CreateUserResponse { | ||
pub user: User, | ||
pub charge: f64, | ||
pub activity_id: uuid::Uuid, | ||
pub etag: String, | ||
pub session_token: String, | ||
} | ||
|
||
impl CreateUserResponse { | ||
pub async fn try_from(response: HttpResponse) -> Result<Self, crate::Error> { | ||
let (_status_code, headers, pinned_stream) = response.deconstruct(); | ||
let body = collect_pinned_stream(pinned_stream).await?; | ||
|
||
Ok(Self { | ||
user: serde_json::from_slice(&body)?, | ||
charge: request_charge_from_headers(&headers)?, | ||
activity_id: activity_id_from_headers(&headers)?, | ||
session_token: session_token_from_headers(&headers)?, | ||
etag: etag_from_headers(&headers)?, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::headers::from_headers::*; | ||
use crate::prelude::*; | ||
use azure_core::{ | ||
collect_pinned_stream, | ||
headers::{etag_from_headers, session_token_from_headers}, | ||
Request as HttpRequest, Response as HttpResponse, | ||
}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct GetUserOptions { | ||
consistency_level: Option<ConsistencyLevel>, | ||
} | ||
|
||
impl GetUserOptions { | ||
pub fn new() -> Self { | ||
Self { | ||
consistency_level: None, | ||
} | ||
} | ||
|
||
setters! { | ||
consistency_level: ConsistencyLevel => Some(consistency_level), | ||
} | ||
|
||
pub(crate) fn decorate_request(&self, request: &mut HttpRequest) -> Result<(), crate::Error> { | ||
azure_core::headers::add_optional_header2(&self.consistency_level, request)?; | ||
request.set_body(bytes::Bytes::from_static(&[]).into()); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct GetUserResponse { | ||
pub user: User, | ||
pub charge: f64, | ||
pub activity_id: uuid::Uuid, | ||
pub etag: String, | ||
pub session_token: String, | ||
} | ||
|
||
impl GetUserResponse { | ||
pub async fn try_from(response: HttpResponse) -> Result<Self, crate::Error> { | ||
let (_status_code, headers, pinned_stream) = response.deconstruct(); | ||
let body = collect_pinned_stream(pinned_stream).await?; | ||
|
||
Ok(Self { | ||
user: serde_json::from_slice(&body)?, | ||
charge: request_charge_from_headers(&headers)?, | ||
activity_id: activity_id_from_headers(&headers)?, | ||
session_token: session_token_from_headers(&headers)?, | ||
etag: etag_from_headers(&headers)?, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::headers::from_headers::*; | ||
use crate::prelude::*; | ||
use azure_core::{ | ||
collect_pinned_stream, | ||
headers::{etag_from_headers, session_token_from_headers}, | ||
Request as HttpRequest, Response as HttpResponse, | ||
}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct ReplaceUserOptions { | ||
consistency_level: Option<ConsistencyLevel>, | ||
} | ||
|
||
impl ReplaceUserOptions { | ||
pub fn new() -> Self { | ||
Self { | ||
consistency_level: None, | ||
} | ||
} | ||
|
||
setters! { | ||
consistency_level: ConsistencyLevel => Some(consistency_level), | ||
} | ||
|
||
pub(crate) fn decorate_request( | ||
&self, | ||
request: &mut HttpRequest, | ||
user_name: &str, | ||
) -> Result<(), crate::Error> { | ||
azure_core::headers::add_optional_header2(&self.consistency_level, request)?; | ||
let body = ReplaceUserBody { id: user_name }; | ||
request.set_body(bytes::Bytes::from(serde_json::to_string(&body)?).into()); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ReplaceUserResponse { | ||
pub user: User, | ||
pub charge: f64, | ||
pub activity_id: uuid::Uuid, | ||
pub etag: String, | ||
pub session_token: String, | ||
} | ||
|
||
impl ReplaceUserResponse { | ||
pub async fn try_from(response: HttpResponse) -> Result<Self, crate::Error> { | ||
let (_status_code, headers, pinned_stream) = response.deconstruct(); | ||
let body = collect_pinned_stream(pinned_stream).await?; | ||
|
||
Ok(Self { | ||
user: serde_json::from_slice(&body)?, | ||
charge: request_charge_from_headers(&headers)?, | ||
activity_id: activity_id_from_headers(&headers)?, | ||
session_token: session_token_from_headers(&headers)?, | ||
etag: etag_from_headers(&headers)?, | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Serialize)] | ||
struct ReplaceUserBody<'a> { | ||
id: &'a str, | ||
} |
Oops, something went wrong.