From 91d8ffe40fd75c42de6041a0a4a33c060f1bb563 Mon Sep 17 00:00:00 2001 From: Sinh Date: Tue, 18 Oct 2022 14:57:14 +0700 Subject: [PATCH] add warehouse client method --- client/warehouse.go | 19 +++++++++++ model/warehouse_request.go | 8 +++++ subject/warehouse.go | 66 ++++++++++++++++++++------------------ 3 files changed, 61 insertions(+), 32 deletions(-) diff --git a/client/warehouse.go b/client/warehouse.go index 944c2cb..beb3a6f 100644 --- a/client/warehouse.go +++ b/client/warehouse.go @@ -3,6 +3,7 @@ package client import ( "encoding/json" "errors" + "fmt" "git.selly.red/Selly-Modules/natsio" "git.selly.red/Selly-Modules/natsio/model" @@ -163,3 +164,21 @@ func (w Warehouse) GetWarehouses(p model.GetWarehousesRequest) (*model.GetWareho } return r.Data, nil } + +// UpdateORDeliveryStatus ... +func (w Warehouse) UpdateORDeliveryStatus(p model.WarehouseORUpdateDeliveryStatus) error { + msg, err := natsio.GetServer().Request(subject.Warehouse.GetWarehouses, toBytes(p)) + if err != nil { + return err + } + var r struct { + Error string `json:"error"` + } + if err = json.Unmarshal(msg.Data, &r); err != nil { + return fmt.Errorf("nats: update_or_delivery_status %v", err) + } + if r.Error != "" { + return errors.New(r.Error) + } + return nil +} diff --git a/model/warehouse_request.go b/model/warehouse_request.go index 4cd857a..b6cecb1 100644 --- a/model/warehouse_request.go +++ b/model/warehouse_request.go @@ -105,3 +105,11 @@ type GetWarehousesRequest struct { Page int64 `json:"page"` Limit int64 `json:"limit"` } + +// WarehouseORUpdateDeliveryStatus ... +type WarehouseORUpdateDeliveryStatus struct { + ORCode string `json:"orCode"` + OrderCode string `json:"orderCode"` + OrderID string `json:"orderId"` + DeliveryStatus string `json:"deliveryStatus"` +} diff --git a/subject/warehouse.go b/subject/warehouse.go index f6f4cc8..bb184b5 100644 --- a/subject/warehouse.go +++ b/subject/warehouse.go @@ -9,39 +9,41 @@ func getWarehouseValue(val string) string { var Warehouse = struct { CreateWarehouseIntoServiceSupplier string UpdateWarehouseIntoServiceSupplier string - CreateOutboundRequest string - UpdateOutboundRequestLogistic string - CancelOutboundRequest string - GetConfiguration string - SyncORStatus string - WebhookTNC string - WebhookGlobalCare string - WebhookOnPoint string - FindOne string - FindByCondition string - Distinct string - Count string - AfterUpdateWarehouse string - AfterCreateWarehouse string - UpdateIsClosedSupplier string - GetWarehouses string + CreateOutboundRequest string + UpdateOutboundRequestLogistic string + CancelOutboundRequest string + GetConfiguration string + SyncORStatus string + WebhookTNC string + WebhookGlobalCare string + WebhookOnPoint string + FindOne string + FindByCondition string + Distinct string + Count string + AfterUpdateWarehouse string + AfterCreateWarehouse string + UpdateIsClosedSupplier string + GetWarehouses string + UpdateORDeliveryStatus string }{ CreateWarehouseIntoServiceSupplier: getWarehouseValue("create_warehouse_into_service_supplier"), UpdateWarehouseIntoServiceSupplier: getWarehouseValue("update_warehouse_into_service_supplier"), - AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"), - AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"), - CreateOutboundRequest: getWarehouseValue("create_outbound_request"), - UpdateOutboundRequestLogistic: getWarehouseValue("update_outbound_request_logistic_info"), - CancelOutboundRequest: getWarehouseValue("cancel_outbound_request"), - GetConfiguration: getWarehouseValue("get_configuration"), - SyncORStatus: getWarehouseValue("sync_or_status"), - WebhookTNC: getWarehouseValue("webhook_tnc"), - WebhookGlobalCare: getWarehouseValue("webhook_global_care"), - WebhookOnPoint: getWarehouseValue("webhook_on_point"), - FindOne: getWarehouseValue("find_one"), - FindByCondition: getWarehouseValue("find_all_by_condition"), - Distinct: getWarehouseValue("distinct"), - Count: getWarehouseValue("count"), - UpdateIsClosedSupplier: getWarehouseValue("update_is_closed_supplier"), - GetWarehouses: getWarehouseValue("get_warehouses"), + AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"), + AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"), + CreateOutboundRequest: getWarehouseValue("create_outbound_request"), + UpdateOutboundRequestLogistic: getWarehouseValue("update_outbound_request_logistic_info"), + CancelOutboundRequest: getWarehouseValue("cancel_outbound_request"), + GetConfiguration: getWarehouseValue("get_configuration"), + SyncORStatus: getWarehouseValue("sync_or_status"), + WebhookTNC: getWarehouseValue("webhook_tnc"), + WebhookGlobalCare: getWarehouseValue("webhook_global_care"), + WebhookOnPoint: getWarehouseValue("webhook_on_point"), + FindOne: getWarehouseValue("find_one"), + FindByCondition: getWarehouseValue("find_all_by_condition"), + Distinct: getWarehouseValue("distinct"), + Count: getWarehouseValue("count"), + UpdateIsClosedSupplier: getWarehouseValue("update_is_closed_supplier"), + GetWarehouses: getWarehouseValue("get_warehouses"), + UpdateORDeliveryStatus: getWarehouseValue("update_or_delivery_status"), }