Skip to main content

shopify_client/admin/discount/
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::discount::{
10        DiscountAutomaticAppCreateResp, DiscountAutomaticAppInput, DiscountAutomaticAppUpdateInput,
11        DiscountAutomaticAppUpdateResp, DiscountNodesResp, GetDiscountMetafieldResp,
12        GetDiscountNodeResp,
13    },
14};
15
16pub struct Discount {
17    pub(crate) ctx: ServiceContext,
18}
19
20impl Discount {
21    pub fn new(
22        shop_url: Arc<String>,
23        version: Arc<String>,
24        access_token: Arc<String>,
25        callbacks: Arc<RequestCallbacks>,
26    ) -> Self {
27        Self::with_ctx(ServiceContext::new(
28            shop_url,
29            version,
30            access_token,
31            callbacks,
32        ))
33    }
34
35    /// Build the service from a shared `ServiceContext`. Cheaper than `new` at
36    /// construction sites that already hold a context (one `Arc` clone per service).
37    pub fn with_ctx(ctx: ServiceContext) -> Self {
38        Self { ctx }
39    }
40
41    pub async fn create_automatic_app_discount(
42        &self,
43        input: &DiscountAutomaticAppInput,
44    ) -> Result<DiscountAutomaticAppCreateResp, APIError> {
45        remote::create_automatic_app_discount(&self.ctx, input).await
46    }
47
48    pub async fn update_automatic_app_discount(
49        &self,
50        input: &DiscountAutomaticAppUpdateInput,
51    ) -> Result<DiscountAutomaticAppUpdateResp, APIError> {
52        remote::update_automatic_app_discount(&self.ctx, input).await
53    }
54
55    pub async fn list_discounts(
56        &self,
57        first: Option<i32>,
58        after: Option<String>,
59        query: Option<String>,
60    ) -> Result<DiscountNodesResp, APIError> {
61        remote::list_discounts(&self.ctx, first, after, query).await
62    }
63
64    pub async fn get_discount_by_id(
65        &self,
66        id: &str,
67        first: Option<i32>,
68        after: Option<String>,
69    ) -> Result<GetDiscountNodeResp, APIError> {
70        remote::get_discount_by_id(&self.ctx, id, first, after).await
71    }
72
73    pub async fn get_discount_metafield(
74        &self,
75        id: &str,
76        namespace: &str,
77        key: &str,
78    ) -> Result<GetDiscountMetafieldResp, APIError> {
79        remote::get_discount_metafield(&self.ctx, id, namespace, key).await
80    }
81}