feat: refactor logistics functions in Viettel FFM module
- Add a new type `CancelORPayload` to the file `model.go` - Add a new constant `pathCancelOR` in the `viettel_ffm.go` file - Change the method from `POST` to `PUT` in the `UpdateORLogisticInfo` function in `viettel_ffm.go` - Add a new function `CancelOR` in the `viettel_ffm.go` file Signed-off-by: Sinh <luuvansinh555@gmail.com>
This commit is contained in:
parent
1034d2e077
commit
178652fcef
|
@ -16,6 +16,10 @@ type UpdateLogisticInfoPayload struct {
|
||||||
TrackingCode string `json:"tracking_code"`
|
TrackingCode string `json:"tracking_code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CancelORPayload struct {
|
||||||
|
OrID int `json:"or_id"`
|
||||||
|
}
|
||||||
|
|
||||||
type ORPayload struct {
|
type ORPayload struct {
|
||||||
OrProductLines []ORProductLine `json:"or_product_lines"`
|
OrProductLines []ORProductLine `json:"or_product_lines"`
|
||||||
AmountPaid float64 `json:"amount_paid"`
|
AmountPaid float64 `json:"amount_paid"`
|
||||||
|
|
|
@ -27,6 +27,7 @@ const (
|
||||||
pathAuth = "/realms/wms/protocol/openid-connect/token"
|
pathAuth = "/realms/wms/protocol/openid-connect/token"
|
||||||
pathUpdateORLogisticInfo = "/wms-core/api/v1/obms/outbound-request/outbound-request-partner/%s/bill"
|
pathUpdateORLogisticInfo = "/wms-core/api/v1/obms/outbound-request/outbound-request-partner/%s/bill"
|
||||||
pathCreateOR = "/wms-core/api/v1/obms/outbound-request/outbound-request-partner"
|
pathCreateOR = "/wms-core/api/v1/obms/outbound-request/outbound-request-partner"
|
||||||
|
pathCancelOR = "/wms-core/api/v1/obms/outbound-request/cancel"
|
||||||
|
|
||||||
logTarget = "viettel-ffm"
|
logTarget = "viettel-ffm"
|
||||||
)
|
)
|
||||||
|
@ -96,12 +97,42 @@ func (c *Client) CreateOR(p ORPayload) (*ORResult, error) {
|
||||||
return &data, nil
|
return &data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) UpdateOutboundRequestLogisticInfo(p UpdateLogisticInfoPayload) error {
|
func (c *Client) UpdateORLogisticInfo(p UpdateLogisticInfoPayload) error {
|
||||||
apiURL := c.getBaseURL() + pathUpdateORLogisticInfo
|
apiURL := c.getBaseURL() + pathUpdateORLogisticInfo
|
||||||
token, err := c.getToken()
|
token, err := c.getToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
natsPayload := model.CommunicationRequestHttp{
|
||||||
|
ResponseImmediately: true,
|
||||||
|
Payload: model.HttpRequest{
|
||||||
|
URL: apiURL,
|
||||||
|
Method: http.MethodPut,
|
||||||
|
Data: pjson.ToJSONString(p),
|
||||||
|
Header: map[string]string{
|
||||||
|
httputil.HeaderKeyAuthorization: fmt.Sprintf("Bearer %s", token),
|
||||||
|
httputil.HeaderKeyContentType: httputil.HeaderValueApplicationJSON,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
LogTarget: logTarget,
|
||||||
|
}
|
||||||
|
r, err := c.requestHttpViaNats(natsPayload)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
res := r.Response
|
||||||
|
if res.StatusCode >= http.StatusBadRequest {
|
||||||
|
return fmt.Errorf("viettelffm.Client.UpdateOutboundRequestLogisticInfo - requestHttpViaNats %s", res.Body)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) CancelOR(p CancelORPayload) error {
|
||||||
|
apiURL := c.getBaseURL() + pathCancelOR
|
||||||
|
token, err := c.getToken()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
natsPayload := model.CommunicationRequestHttp{
|
natsPayload := model.CommunicationRequestHttp{
|
||||||
ResponseImmediately: true,
|
ResponseImmediately: true,
|
||||||
Payload: model.HttpRequest{
|
Payload: model.HttpRequest{
|
||||||
|
@ -121,7 +152,7 @@ func (c *Client) UpdateOutboundRequestLogisticInfo(p UpdateLogisticInfoPayload)
|
||||||
}
|
}
|
||||||
res := r.Response
|
res := r.Response
|
||||||
if res.StatusCode >= http.StatusBadRequest {
|
if res.StatusCode >= http.StatusBadRequest {
|
||||||
return fmt.Errorf("viettelffm.Client.UpdateOutboundRequestLogisticInfo - requestHttpViaNats %s", res.Body)
|
return fmt.Errorf("viettelffm.Client.CancelOR - requestHttpViaNats %s", res.Body)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue