dceapi_rs/services/
delivery.rs1use crate::error::{Error, Result};
4use crate::http::{BaseClient, RequestOptions};
5use crate::models::{
6 DeliveryCost, DeliveryData, DeliveryDataRequest, DeliveryMatch, DeliveryMatchRequest,
7 WarehousePremium, WarehouseReceipt, WarehouseReceiptRequest,
8};
9
10const PATH_GET_DELIVERY_DATA: &str = "/dceapi/forward/publicweb/deliverystat/delivery";
12
13const PATH_GET_DELIVERY_MATCH: &str = "/dceapi/forward/publicweb/deliverystat/deliveryMatch";
15
16const PATH_GET_WAREHOUSE_RECEIPT: &str = "/dceapi/forward/publicweb/deliverystat/warehouseReceipt";
18
19const PATH_GET_DELIVERY_COST: &str = "/dceapi/forward/publicweb/deliverypara/deliveryCosts";
21
22const PATH_GET_WAREHOUSE_PREMIUM: &str = "/dceapi/forward/publicweb/deliverypara/floatingAgio";
24
25#[derive(Debug, Clone)]
27pub struct DeliveryService {
28 client: BaseClient,
29}
30
31impl DeliveryService {
32 pub fn new(client: BaseClient) -> Self {
34 DeliveryService { client }
35 }
36
37 pub async fn get_delivery_data(
43 &self,
44 req: &DeliveryDataRequest,
45 opts: Option<RequestOptions>,
46 ) -> Result<Vec<DeliveryData>> {
47 self.client.do_post(PATH_GET_DELIVERY_DATA, req, opts).await
48 }
49
50 pub async fn get_delivery_match(
56 &self,
57 req: &DeliveryMatchRequest,
58 opts: Option<RequestOptions>,
59 ) -> Result<Vec<DeliveryMatch>> {
60 self.client.do_post(PATH_GET_DELIVERY_MATCH, req, opts).await
61 }
62
63 pub async fn get_warehouse_receipt(
69 &self,
70 req: &WarehouseReceiptRequest,
71 opts: Option<RequestOptions>,
72 ) -> Result<Vec<WarehouseReceipt>> {
73 self.client.do_post(PATH_GET_WAREHOUSE_RECEIPT, req, opts).await
74 }
75
76 pub async fn get_delivery_cost(
82 &self,
83 variety: &str,
84 opts: Option<RequestOptions>,
85 ) -> Result<DeliveryCost> {
86 if variety.is_empty() {
87 return Err(Error::validation("variety", "variety is required"));
88 }
89
90 #[derive(serde::Serialize)]
91 #[serde(rename_all = "camelCase")]
92 struct Request<'a> {
93 variety_code: &'a str,
94 }
95
96 let req = Request { variety_code: variety };
97 self.client.do_post(PATH_GET_DELIVERY_COST, &req, opts).await
98 }
99
100 pub async fn get_warehouse_premium(
106 &self,
107 variety: &str,
108 opts: Option<RequestOptions>,
109 ) -> Result<Vec<WarehousePremium>> {
110 if variety.is_empty() {
111 return Err(Error::validation("variety", "variety is required"));
112 }
113
114 #[derive(serde::Serialize)]
115 #[serde(rename_all = "camelCase")]
116 struct Request<'a> {
117 variety_code: &'a str,
118 }
119
120 let req = Request { variety_code: variety };
121 self.client.do_post(PATH_GET_WAREHOUSE_PREMIUM, &req, opts).await
122 }
123}