azure_cosmos_mirror/operations/
get_attachment.rs

1use crate::headers::from_headers::*;
2use crate::prelude::*;
3use crate::resources::document::IndexingDirective;
4use crate::resources::Attachment;
5use crate::ResourceQuota;
6use azure_core::headers::{
7    content_type_from_headers, etag_from_headers, session_token_from_headers,
8};
9use azure_core::SessionToken;
10use azure_core::{prelude::*, Response as HttpResponse};
11use time::OffsetDateTime;
12
13operation! {
14    GetAttachment,
15    client: AttachmentClient,
16    ?if_match_condition: IfMatchCondition,
17    ?consistency_level: ConsistencyLevel
18}
19
20impl GetAttachmentBuilder {
21    pub fn into_future(self) -> GetAttachment {
22        Box::pin(async move {
23            let mut request = self.client.attachment_request(azure_core::Method::Get);
24
25            request.insert_headers(&self.if_match_condition);
26            if let Some(cl) = &self.consistency_level {
27                request.insert_headers(cl);
28            }
29
30            crate::cosmos_entity::add_as_partition_key_header_serialized(
31                self.client.document_client().partition_key_serialized(),
32                &mut request,
33            );
34            let response = self
35                .client
36                .pipeline()
37                .send(
38                    self.context.clone().insert(ResourceType::Attachments),
39                    &mut request,
40                )
41                .await?;
42
43            GetAttachmentResponse::try_from(response).await
44        })
45    }
46}
47
48#[derive(Debug, Clone, PartialEq)]
49pub struct GetAttachmentResponse {
50    pub attachment: Attachment,
51
52    pub content_type: String,
53    pub content_location: Option<String>,
54    pub last_change: OffsetDateTime,
55    pub etag: String,
56    pub resource_quota: Vec<ResourceQuota>,
57    pub resource_usage: Vec<ResourceQuota>,
58    pub lsn: u64,
59    pub alt_content_path: String,
60    pub content_path: String,
61    pub global_committed_lsn: u64,
62    pub number_of_read_regions: u32,
63    pub item_lsn: u64,
64    pub transport_request_id: u64,
65    pub cosmos_llsn: u64,
66    pub cosmos_item_llsn: u64,
67    pub session_token: SessionToken,
68    pub request_charge: f64,
69    pub indexing_directive: Option<IndexingDirective>,
70    pub service_version: String,
71    pub activity_id: uuid::Uuid,
72    pub gateway_version: String,
73    pub date: OffsetDateTime,
74}
75
76impl GetAttachmentResponse {
77    pub async fn try_from(response: HttpResponse) -> azure_core::Result<Self> {
78        let (_status_code, headers, body) = response.deconstruct();
79        let body = body.collect().await?;
80
81        Ok(Self {
82            attachment: serde_json::from_slice(&body)?,
83            content_type: content_type_from_headers(&headers)?,
84            content_location: content_location_from_headers(&headers)?,
85            last_change: last_state_change_from_headers(&headers)?,
86            etag: etag_from_headers(&headers)?,
87            resource_quota: resource_quota_from_headers(&headers)?,
88            resource_usage: resource_usage_from_headers(&headers)?,
89            lsn: lsn_from_headers(&headers)?,
90            alt_content_path: alt_content_path_from_headers(&headers)?,
91            content_path: content_path_from_headers(&headers)?,
92            global_committed_lsn: global_committed_lsn_from_headers(&headers)?,
93            number_of_read_regions: number_of_read_regions_from_headers(&headers)?,
94            item_lsn: item_lsn_from_headers(&headers)?,
95            transport_request_id: transport_request_id_from_headers(&headers)?,
96            cosmos_llsn: cosmos_llsn_from_headers(&headers)?,
97            cosmos_item_llsn: cosmos_item_llsn_from_headers(&headers)?,
98            session_token: session_token_from_headers(&headers)?,
99            request_charge: request_charge_from_headers(&headers)?,
100            indexing_directive: indexing_directive_from_headers_optional(&headers)?,
101            service_version: service_version_from_headers(&headers)?,
102            activity_id: activity_id_from_headers(&headers)?,
103            gateway_version: gateway_version_from_headers(&headers)?,
104            date: date_from_headers(&headers)?,
105        })
106    }
107}