From 367dc7edd979e79712ffb9cd653fff4bf465dabf Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 7 Sep 2022 12:00:40 +0700 Subject: [PATCH 1/3] add order func --- client/order.go | 16 ++++++++++++++++ model/order_request.go | 7 +++++++ subject/order.go | 14 ++++++++------ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/client/order.go b/client/order.go index 5400f52..8834495 100644 --- a/client/order.go +++ b/client/order.go @@ -66,3 +66,19 @@ func (o Order) ChangeDeliveryStatus(p model.OrderChangeDeliveryStatus) error { } return nil } + +// UpdateLogisticInfoFailed ... +func (o Order) UpdateLogisticInfoFailed(p model.OrderUpdateLogisticInfoFailed) error { + msg, err := natsio.GetServer().Request(subject.Order.UpdateLogisticInfoFailed, toBytes(p)) + if err != nil { + return err + } + var r model.CommonResponseData + if err = json.Unmarshal(msg.Data, &r); err != nil { + return err + } + if r.Error != "" { + return errors.New(r.Error) + } + return nil +} diff --git a/model/order_request.go b/model/order_request.go index 2bba161..48bbb79 100644 --- a/model/order_request.go +++ b/model/order_request.go @@ -26,3 +26,10 @@ type OrderChangeDeliveryStatus struct { type OrderORData struct { Link string `json:"link"` } + +// OrderUpdateLogisticInfoFailed ... +type OrderUpdateLogisticInfoFailed struct { + OrderID string `json:"orderId"` + ORCode string `json:"orCode"` + Reason string `json:"reason"` +} diff --git a/subject/order.go b/subject/order.go index 7ba7886..40f190e 100644 --- a/subject/order.go +++ b/subject/order.go @@ -7,11 +7,13 @@ func getOrderValue(val string) string { } var Order = struct { - UpdateORStatus string - CancelDelivery string - ChangeDeliveryStatus string + UpdateORStatus string + CancelDelivery string + ChangeDeliveryStatus string + UpdateLogisticInfoFailed string }{ - UpdateORStatus: getOrderValue("update_outbound_request_status"), - CancelDelivery: getOrderValue("cancel_delivery"), - ChangeDeliveryStatus: getOrderValue("change_delivery_status"), + UpdateORStatus: getOrderValue("update_outbound_request_status"), + CancelDelivery: getOrderValue("cancel_delivery"), + ChangeDeliveryStatus: getOrderValue("change_delivery_status"), + UpdateLogisticInfoFailed: getOrderValue("update_logistic_info_failed"), } -- 2.34.1 From 9b40f5f9ba519d08d818ec01e81a67f00557b474 Mon Sep 17 00:00:00 2001 From: phuanbui Date: Wed, 7 Sep 2022 14:01:29 +0700 Subject: [PATCH 2/3] fix get-location-warehouse --- client/location.go | 68 ++++++++++++++++++++++++++++++++++++++ model/location_request.go | 15 +++++++++ model/location_response.go | 15 +++++++++ subject/location.go | 10 ++++-- 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/client/location.go b/client/location.go index 7fc3474..2e8d30e 100644 --- a/client/location.go +++ b/client/location.go @@ -17,6 +17,7 @@ func GetLocation() Location { return Location{} } +// GetLocationByCode ... func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*model.ResponseLocationAddress, error) { msg, err := natsio.GetServer().Request(subject.Location.GetLocationByCode, toBytes(payload)) if err != nil { @@ -36,3 +37,70 @@ func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*mode } return r.Data, nil } + +// GetProvincesByCodes ... ... +func (l Location) GetProvincesByCodes(p model.ProvinceRequestPayload) (*model.LocationProvinceResponse, error) { + msg, err := natsio.GetServer().Request(subject.Location.GetProvincesByCodes, toBytes(p)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.LocationProvinceResponse `json:"data"'` + Error string `json:"error"` + } + + if err := json.Unmarshal(msg.Data, &r); err != nil { + return nil, err + } + + if r.Error != "" { + return nil, errors.New(r.Error) + } + return r.Data, nil +} + +// GetDistrictsByCodes ... +func (l Location) GetDistrictsByCodes(p model.DistrictRequestPayload) (*model.LocationDistrictResponse, error) { + msg, err := natsio.GetServer().Request(subject.Location.GetDistrictsByCodes, toBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data *model.LocationDistrictResponse `json:"data"` + Error string `json:"error"` + } + + if err := json.Unmarshal(msg.Data, &r); err != nil { + return nil, err + } + + if r.Error != "" { + return nil, errors.New(r.Error) + } + + return r.Data, nil +} + +// GetWardsByCodes ... +func (l Location) GetWardsByCodes(p model.WardRequestPayload) (*model.LocationWardResponse, error) { + msg, err := natsio.GetServer().Request(subject.Location.GetWardsByCodes, toBytes(p)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.LocationWardResponse `json:"data"` + Error string `json:"error"` + } + + if err := json.Unmarshal(msg.Data, &r); err != nil { + return nil, err + } + + if r.Error != "" { + return nil, errors.New(r.Error) + } + + return r.Data, nil +} diff --git a/model/location_request.go b/model/location_request.go index e6781ca..0d55d1d 100644 --- a/model/location_request.go +++ b/model/location_request.go @@ -6,3 +6,18 @@ type LocationRequestPayload struct { District int `json:"district"` Ward int `json:"ward"` } + +// ProvinceRequestPayload ... +type ProvinceRequestPayload struct { + Codes []int `json:"Codes"` +} + +// DistrictRequestPayload ... +type DistrictRequestPayload struct { + Codes []int `json:"Codes"` +} + +// WardRequestPayload ... +type WardRequestPayload struct { + Codes []int `json:"Codes"` +} diff --git a/model/location_response.go b/model/location_response.go index 436d1f7..49e3cbd 100644 --- a/model/location_response.go +++ b/model/location_response.go @@ -26,3 +26,18 @@ type LocationWard struct { Name string `json:"name"` Code int `json:"code"` } + +// LocationProvinceResponse ... +type LocationProvinceResponse struct { + Province []LocationProvince `json:"province"` +} + +// LocationDistrictResponse ... +type LocationDistrictResponse struct { + District []LocationDistrict `json:"district"` +} + +// LocationWardResponse ... +type LocationWardResponse struct { + Ward []LocationWard `json:"ward"` +} diff --git a/subject/location.go b/subject/location.go index 1989df3..22141ad 100644 --- a/subject/location.go +++ b/subject/location.go @@ -7,7 +7,13 @@ func getLocationValue(val string) string { } var Location = struct { - GetLocationByCode string + GetLocationByCode string + GetProvincesByCodes string + GetDistrictsByCodes string + GetWardsByCodes string }{ - GetLocationByCode: getLocationValue("get_location_warehouse"), + GetLocationByCode: getLocationValue("get_location_warehouse"), + GetProvincesByCodes: getLocationValue("get_provinces_warehouse"), + GetDistrictsByCodes: getLocationValue("get_districts_warehouse"), + GetWardsByCodes: getLocationValue("get_wards_warehouse"), } -- 2.34.1 From 218123ccfbd1ac6a8233446139c4de4edd8cae8f Mon Sep 17 00:00:00 2001 From: phuanbui Date: Wed, 7 Sep 2022 14:10:23 +0700 Subject: [PATCH 3/3] fix --- model/location_request.go | 6 +++--- model/location_response.go | 6 +++--- subject/location.go | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/model/location_request.go b/model/location_request.go index 0d55d1d..4533db7 100644 --- a/model/location_request.go +++ b/model/location_request.go @@ -9,15 +9,15 @@ type LocationRequestPayload struct { // ProvinceRequestPayload ... type ProvinceRequestPayload struct { - Codes []int `json:"Codes"` + Codes []int `json:"codes"` } // DistrictRequestPayload ... type DistrictRequestPayload struct { - Codes []int `json:"Codes"` + Codes []int `json:"codes"` } // WardRequestPayload ... type WardRequestPayload struct { - Codes []int `json:"Codes"` + Codes []int `json:"codes"` } diff --git a/model/location_response.go b/model/location_response.go index 49e3cbd..484d89e 100644 --- a/model/location_response.go +++ b/model/location_response.go @@ -29,15 +29,15 @@ type LocationWard struct { // LocationProvinceResponse ... type LocationProvinceResponse struct { - Province []LocationProvince `json:"province"` + Provinces []LocationProvince `json:"provinces"` } // LocationDistrictResponse ... type LocationDistrictResponse struct { - District []LocationDistrict `json:"district"` + Districts []LocationDistrict `json:"districts"` } // LocationWardResponse ... type LocationWardResponse struct { - Ward []LocationWard `json:"ward"` + Wards []LocationWard `json:"wards"` } diff --git a/subject/location.go b/subject/location.go index 22141ad..b19a59b 100644 --- a/subject/location.go +++ b/subject/location.go @@ -13,7 +13,7 @@ var Location = struct { GetWardsByCodes string }{ GetLocationByCode: getLocationValue("get_location_warehouse"), - GetProvincesByCodes: getLocationValue("get_provinces_warehouse"), - GetDistrictsByCodes: getLocationValue("get_districts_warehouse"), - GetWardsByCodes: getLocationValue("get_wards_warehouse"), + GetProvincesByCodes: getLocationValue("get_provinces_by_codes"), + GetDistrictsByCodes: getLocationValue("get_districts_by_codes"), + GetWardsByCodes: getLocationValue("get_wards_by_codes"), } -- 2.34.1