Skip to main content

shopify_client/admin/order/
mod.rs

1pub mod remote;
2
3use crate::common::ServiceContext;
4
5use std::sync::Arc;
6
7use crate::{
8    common::types::{APIError, RequestCallbacks},
9    types::order::{GetOrderResp, OrderQueryResp, PatchOrderRequest},
10};
11
12pub struct Order {
13    pub(crate) ctx: ServiceContext,
14}
15
16impl Order {
17    pub fn new(
18        shop_url: Arc<String>,
19        version: Arc<String>,
20        access_token: Arc<String>,
21        callbacks: Arc<RequestCallbacks>,
22    ) -> Self {
23        Self::with_ctx(ServiceContext::new(
24            shop_url,
25            version,
26            access_token,
27            callbacks,
28        ))
29    }
30
31    /// Build the service from a shared `ServiceContext`. Cheaper than `new` at
32    /// construction sites that already hold a context (one `Arc` clone per service).
33    pub fn with_ctx(ctx: ServiceContext) -> Self {
34        Self { ctx }
35    }
36
37    pub async fn get_with_id(&self, order_id: &String) -> Result<GetOrderResp, APIError> {
38        remote::get_order_with_id(&self.ctx, order_id).await
39    }
40
41    pub async fn get_with_name(&self, order_name: &String) -> Result<OrderQueryResp, APIError> {
42        remote::get_order_with_name(&self.ctx, order_name).await
43    }
44
45    pub async fn patch(
46        &self,
47        order_id: &String,
48        patch_request: &PatchOrderRequest,
49    ) -> Result<GetOrderResp, APIError> {
50        remote::patch_order(&self.ctx, order_id, patch_request).await
51    }
52}