From 1e3bfd73927ddaefa130ecaee5da8c8be1f48ad3 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Wed, 30 Mar 2022 17:55:28 +0700 Subject: [PATCH 01/31] [Update] --- natsio.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/natsio.go b/natsio.go index 33bdbb2..120828f 100644 --- a/natsio.go +++ b/natsio.go @@ -3,6 +3,7 @@ package natsio import ( "errors" "fmt" + "time" "github.com/logrusorgru/aurora" "github.com/nats-io/nats.go" @@ -32,6 +33,8 @@ func Connect(cfg Config) error { // Connect options opts := make([]nats.Option, 0) + opts = append(opts, nats.Timeout(1*time.Minute)) + // Has authentication if cfg.User != "" { opts = append(opts, nats.UserInfo(cfg.User, cfg.Password)) From 2a9897e137f822640609249b6c49f2978c6bc1c9 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Wed, 30 Mar 2022 19:17:14 +0700 Subject: [PATCH 02/31] [Update] Config --- config.go | 5 +++++ natsio.go | 6 ++---- server_reqres.go | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/config.go b/config.go index 295f751..898b767 100644 --- a/config.go +++ b/config.go @@ -1,5 +1,7 @@ package natsio +import "time" + // Config ... type Config struct { // Connect url @@ -13,6 +15,9 @@ type Config struct { // TLS config TLS *TLSConfig + + // RequestTimeout + RequestTimeout time.Duration } // TLSConfig ... diff --git a/natsio.go b/natsio.go index 120828f..5ccc45d 100644 --- a/natsio.go +++ b/natsio.go @@ -3,8 +3,6 @@ package natsio import ( "errors" "fmt" - "time" - "github.com/logrusorgru/aurora" "github.com/nats-io/nats.go" ) @@ -12,6 +10,7 @@ import ( // Server ... type Server struct { instance *nats.Conn + Config Config } // JetStream ... @@ -33,8 +32,6 @@ func Connect(cfg Config) error { // Connect options opts := make([]nats.Option, 0) - opts = append(opts, nats.Timeout(1*time.Minute)) - // Has authentication if cfg.User != "" { opts = append(opts, nats.UserInfo(cfg.User, cfg.Password)) @@ -56,6 +53,7 @@ func Connect(cfg Config) error { // Set client natsServer.instance = nc + natsServer.Config = cfg // Create jet stream context js, err := nc.JetStream(nats.PublishAsyncMaxPending(256)) diff --git a/server_reqres.go b/server_reqres.go index 303c954..6e227a8 100644 --- a/server_reqres.go +++ b/server_reqres.go @@ -13,7 +13,11 @@ const requestTimeout = 10 * time.Second // Request ... func (sv Server) Request(subject string, payload []byte) (*nats.Msg, error) { - return sv.instance.Request(subject, payload, requestTimeout) + timeout := requestTimeout + if sv.Config.RequestTimeout > 0 { + timeout = sv.Config.RequestTimeout + } + return sv.instance.Request(subject, payload, timeout) } // Reply ... From ad51f45871bb25c6aaa68797be82187c859d7134 Mon Sep 17 00:00:00 2001 From: Sinh Date: Thu, 25 Aug 2022 16:57:42 +0700 Subject: [PATCH 03/31] add request json encode --- json_encoder.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/json_encoder.go b/json_encoder.go index 4a0bdb8..af13573 100644 --- a/json_encoder.go +++ b/json_encoder.go @@ -26,3 +26,8 @@ func (e JSONEncoder) Subscribe(subject string, cb nats.Handler) (*nats.Subscript func (e JSONEncoder) Publish(reply string, data interface{}) error { return e.encConn.Publish(reply, data) } + +// Request ... +func (e JSONEncoder) Request(subject string, data interface{}, res interface{}) error { + return e.encConn.Request(subject, data, res, requestTimeout) +} From 5ca473ffc1e3d8bf3402b464c0c15b3179d9a251 Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 26 Aug 2022 10:28:49 +0700 Subject: [PATCH 04/31] define model --- model/warehouse_request.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/model/warehouse_request.go b/model/warehouse_request.go index 5612532..51bc667 100644 --- a/model/warehouse_request.go +++ b/model/warehouse_request.go @@ -12,6 +12,19 @@ type OutboundRequestPayload struct { TPLCode string `json:"tplCode"` Customer CustomerInfo `json:"customer"` Items []OutboundRequestItem `json:"items"` + Insurance *InsuranceOpts +} + +// InsuranceOpts ... +type InsuranceOpts struct { + VehicleTypeID string `json:"vehicleTypeId"` + VehicleTypeName string `json:"vehicleTypeName"` + InsuranceTypeID string `json:"insuranceTypeId"` + YearsOfInsurance int `json:"yearsOfInsurance"` + License string `json:"license"` + Chassis string `json:"chassis"` + Engine string `json:"engine"` + BeginDate string `json:"beginDate"` } // OutboundRequestItem ... @@ -25,6 +38,7 @@ type OutboundRequestItem struct { type CustomerInfo struct { Name string `json:"name"` PhoneNumber string `json:"phoneNumber"` + Email string `json:"email"` Address AddressDetail `json:"address"` } From e860b97c5b67436dfe76303513dfcb2d509379a1 Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 26 Aug 2022 10:31:36 +0700 Subject: [PATCH 05/31] update json tag --- model/warehouse_response.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/model/warehouse_response.go b/model/warehouse_response.go index deaeff1..2e19c9a 100644 --- a/model/warehouse_response.go +++ b/model/warehouse_response.go @@ -34,8 +34,8 @@ type WarehouseSupplier struct { type WarehouseOrder struct { MinimumValue float64 `json:"minimumValue"` PaymentMethod WarehousePaymentMethod `json:"paymentMethod"` - IsLimitNumberOfPurchases bool `json:"isLimitNumberOfPurchases" json:"isLimitNumberOfPurchases"` - LimitNumberOfPurchases int64 `json:"limitNumberOfPurchases" json:"limitNumberOfPurchases"` + IsLimitNumberOfPurchases bool `json:"isLimitNumberOfPurchases"` + LimitNumberOfPurchases int64 `json:"limitNumberOfPurchases"` } // WarehousePaymentMethod ... @@ -47,9 +47,9 @@ type WarehousePaymentMethod struct { // WarehouseDelivery ... type WarehouseDelivery struct { DeliveryMethods []string `json:"deliveryMethods"` - PriorityServiceCodes []string `json:"priorityDeliveryServiceCodes"` - EnabledSources []int `json:"enabledDeliverySources"` - Types []string `json:"type"` + PriorityServiceCodes []string `json:"priorityServiceCodes"` + EnabledSources []int `json:"enabledSources"` + Types []string `json:"types"` } // WarehousePartner ... From 924935fdf3bc03b455d680d66e44b3540b01dd7b Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 26 Aug 2022 11:25:09 +0700 Subject: [PATCH 06/31] change subject cancel delivery --- client/order.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/order.go b/client/order.go index 949bb51..3459f52 100644 --- a/client/order.go +++ b/client/order.go @@ -37,7 +37,7 @@ func (o Order) UpdateORStatus(p model.OrderUpdateORStatus) error { // CancelDelivery ... func (o Order) CancelDelivery(p model.OrderCancelDelivery) error { - msg, err := natsio.GetServer().Request(subject.OrderUpdateORStatus, toBytes(p)) + msg, err := natsio.GetServer().Request(subject.OrderCancelDelivery, toBytes(p)) if err != nil { return err } From 3458f885ec240e518d55e101a2468128dd457bf9 Mon Sep 17 00:00:00 2001 From: phuanbui Date: Fri, 26 Aug 2022 17:15:49 +0700 Subject: [PATCH 07/31] nats-location-supplier --- client/location.go | 38 ++++++++++++++++++++++++++++++++++++++ client/supplier.go | 34 ++++++++++++++++++++++++++++++++++ model/location_request.go | 8 ++++++++ model/location_response.go | 31 +++++++++++++++++++++++++++++++ subject/location.go | 8 ++++++++ subject/supplier.go | 8 ++++++++ 6 files changed, 127 insertions(+) create mode 100644 client/location.go create mode 100644 client/supplier.go create mode 100644 model/location_request.go create mode 100644 model/location_response.go create mode 100644 subject/location.go create mode 100644 subject/supplier.go diff --git a/client/location.go b/client/location.go new file mode 100644 index 0000000..f5a6688 --- /dev/null +++ b/client/location.go @@ -0,0 +1,38 @@ +package client + +import ( + "encoding/json" + "errors" + + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" +) + +// Location ... +type Location struct{} + +// GetLocation ... +func GetLocation() Location { + return Location{} +} + +func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*model.ResponseLocationAddress, error) { + msg, err := natsio.GetServer().Request(subject.GetLocationWarehouse, toBytes(payload)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseLocationAddress `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/client/supplier.go b/client/supplier.go new file mode 100644 index 0000000..07c7a39 --- /dev/null +++ b/client/supplier.go @@ -0,0 +1,34 @@ +package client + +import ( + "encoding/json" + "errors" + + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" +) + +// Supplier ... +type Supplier struct{} + +func (s Supplier) GetSupplierInfo(supplierID string) (*model.ResponseSupplierInfo, error) { + msg, err := natsio.GetServer().Request(subject.GetSupplierInfo, toBytes(supplierID)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseSupplierInfo `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 new file mode 100644 index 0000000..e6781ca --- /dev/null +++ b/model/location_request.go @@ -0,0 +1,8 @@ +package model + +// LocationRequestPayload ... +type LocationRequestPayload struct { + Province int `json:"province"` + District int `json:"district"` + Ward int `json:"ward"` +} diff --git a/model/location_response.go b/model/location_response.go new file mode 100644 index 0000000..fcb4dbb --- /dev/null +++ b/model/location_response.go @@ -0,0 +1,31 @@ +package model + +type ResponseLocationAddress struct { + Province LocationProvince `json:"province"` + District LocationDistrict `json:"district"` + Ward LocationWard `json:"ward"` +} + +// LocationProvince ... +type LocationProvince struct { + ID string `json:"id"` + Name string `json:"name"` +} + +// LocationDistrict ... +type LocationDistrict struct { + ID string `json:"id"` + Name string `json:"name"` +} + +// LocationWard ... +type LocationWard struct { + ID string `json:"id"` + Name string `json:"name"` +} + +// ResponseSupplierInfo ... +type ResponseSupplierInfo struct { + ID string `json:"id"` + Name string `json:"name"` +} diff --git a/subject/location.go b/subject/location.go new file mode 100644 index 0000000..d24a86b --- /dev/null +++ b/subject/location.go @@ -0,0 +1,8 @@ +package subject + +const ( + locationPrefix = "location_" +) +const ( + GetLocationWarehouse = locationPrefix + "get_address" +) diff --git a/subject/supplier.go b/subject/supplier.go new file mode 100644 index 0000000..93ce7de --- /dev/null +++ b/subject/supplier.go @@ -0,0 +1,8 @@ +package subject + +const ( + supplierPrefix = "supplier" +) +const ( + GetSupplierInfo = supplierPrefix + "get_info" +) From d79739aa0f9a74da06b154efbba07251e0369055 Mon Sep 17 00:00:00 2001 From: phuanbui Date: Fri, 26 Aug 2022 17:36:02 +0700 Subject: [PATCH 08/31] refactor-code --- client/location.go | 2 +- client/supplier.go | 2 +- subject/config.go | 4 ++++ subject/location.go | 17 +++++++++++------ subject/supplier.go | 17 +++++++++++------ 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/client/location.go b/client/location.go index f5a6688..7fc3474 100644 --- a/client/location.go +++ b/client/location.go @@ -18,7 +18,7 @@ func GetLocation() Location { } func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*model.ResponseLocationAddress, error) { - msg, err := natsio.GetServer().Request(subject.GetLocationWarehouse, toBytes(payload)) + msg, err := natsio.GetServer().Request(subject.Location.GetLocationByCode, toBytes(payload)) if err != nil { return nil, err } diff --git a/client/supplier.go b/client/supplier.go index 07c7a39..23390e0 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -13,7 +13,7 @@ import ( type Supplier struct{} func (s Supplier) GetSupplierInfo(supplierID string) (*model.ResponseSupplierInfo, error) { - msg, err := natsio.GetServer().Request(subject.GetSupplierInfo, toBytes(supplierID)) + msg, err := natsio.GetServer().Request(subject.Supplier.GetSupplierInfo, toBytes(supplierID)) if err != nil { return nil, err } diff --git a/subject/config.go b/subject/config.go index fd6ccdf..dfeea56 100644 --- a/subject/config.go +++ b/subject/config.go @@ -4,8 +4,12 @@ var prefixes = struct { Communication string Order string Warehouse string + Location string + Supplier string }{ Communication: "communication", Order: "order", Warehouse: "warehouse", + Location: "location", + Supplier: "supplier", } diff --git a/subject/location.go b/subject/location.go index d24a86b..1989df3 100644 --- a/subject/location.go +++ b/subject/location.go @@ -1,8 +1,13 @@ package subject -const ( - locationPrefix = "location_" -) -const ( - GetLocationWarehouse = locationPrefix + "get_address" -) +import "fmt" + +func getLocationValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Location, val) +} + +var Location = struct { + GetLocationByCode string +}{ + GetLocationByCode: getLocationValue("get_location_warehouse"), +} diff --git a/subject/supplier.go b/subject/supplier.go index 93ce7de..4b4cf52 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -1,8 +1,13 @@ package subject -const ( - supplierPrefix = "supplier" -) -const ( - GetSupplierInfo = supplierPrefix + "get_info" -) +import "fmt" + +func getSupplierValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Supplier, val) +} + +var Supplier = struct { + GetSupplierInfo string +}{ + GetSupplierInfo: getSupplierValue("get_supplier_info"), +} From 3c4e331c6f92aaf6e8bcc3d42a35ab2951e61c2c Mon Sep 17 00:00:00 2001 From: phuanbui Date: Fri, 26 Aug 2022 23:13:18 +0700 Subject: [PATCH 09/31] get supplier info --- go.mod | 2 +- go.sum | 39 +++++++++++++++++++++++++++++++------- model/location_response.go | 6 ------ model/supplier_request.go | 10 ++++++++++ model/supplier_response.go | 7 +++++++ 5 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 model/supplier_request.go create mode 100644 model/supplier_response.go diff --git a/go.mod b/go.mod index ef3b649..ac44201 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,9 @@ go 1.16 require ( github.com/golang/protobuf v1.5.2 // indirect - github.com/logrusorgru/aurora v2.0.3+incompatible github.com/nats-io/nats-server/v2 v2.6.1 // indirect github.com/nats-io/nats.go v1.13.0 github.com/thoas/go-funk v0.9.1 + go.mongodb.org/mongo-driver v1.10.1 google.golang.org/protobuf v1.27.1 // indirect ) diff --git a/go.sum b/go.sum index a4b26ff..edfc98b 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,6 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= @@ -9,17 +10,23 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s= github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= -github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= -github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= +github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= +github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0= github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/nats-io/jwt v1.2.2 h1:w3GMTO969dFg+UOKTmmyuu7IGdusK+7Ytlt//OYH/uU= github.com/nats-io/jwt v1.2.2/go.mod h1:/xX356yQA6LuXI9xWW7mZNpxgF2mBmGecH+Fj34sP5Q= github.com/nats-io/jwt/v2 v2.0.3 h1:i/O6cmIsjpcQyWDYNcq2JyZ3/VTF8SJ4JWluI5OhpvI= @@ -34,29 +41,44 @@ github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8= github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M= github.com/thoas/go-funk v0.9.1/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= +github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= +go.mongodb.org/mongo-driver v1.10.1 h1:NujsPveKwHaWuKUer/ceo9DzEe7HIj1SlJ6uvXZG0S4= +go.mongodb.org/mongo-driver v1.10.1/go.mod h1:z4XpeoU6w+9Vht+jAFyLgVrD+jGSQQe0+CBWFHNiHt8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -72,5 +94,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/model/location_response.go b/model/location_response.go index fcb4dbb..82866ec 100644 --- a/model/location_response.go +++ b/model/location_response.go @@ -23,9 +23,3 @@ type LocationWard struct { ID string `json:"id"` Name string `json:"name"` } - -// ResponseSupplierInfo ... -type ResponseSupplierInfo struct { - ID string `json:"id"` - Name string `json:"name"` -} diff --git a/model/supplier_request.go b/model/supplier_request.go new file mode 100644 index 0000000..2fede05 --- /dev/null +++ b/model/supplier_request.go @@ -0,0 +1,10 @@ +package model + +import ( + "go.mongodb.org/mongo-driver/bson/primitive" +) + +// GetSupplierRequest ... +type GetSupplierRequest struct { + ID primitive.ObjectID `json:"_id"` +} diff --git a/model/supplier_response.go b/model/supplier_response.go new file mode 100644 index 0000000..de2f579 --- /dev/null +++ b/model/supplier_response.go @@ -0,0 +1,7 @@ +package model + +// ResponseSupplierInfo ... +type ResponseSupplierInfo struct { + ID string `json:"id"` + Name string `json:"name"` +} From cfab69233195c5ab247eed98b29e45bac4f8f073 Mon Sep 17 00:00:00 2001 From: phuanbui Date: Fri, 26 Aug 2022 23:37:01 +0700 Subject: [PATCH 10/31] edit types param supplier --- client/supplier.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/supplier.go b/client/supplier.go index 23390e0..01da757 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -12,7 +12,12 @@ import ( // Supplier ... type Supplier struct{} -func (s Supplier) GetSupplierInfo(supplierID string) (*model.ResponseSupplierInfo, error) { +// GetSupplier ... +func GetSupplier() Supplier { + return Supplier{} +} + +func (s Supplier) GetSupplierInfo(supplierID model.GetSupplierRequest) (*model.ResponseSupplierInfo, error) { msg, err := natsio.GetServer().Request(subject.Supplier.GetSupplierInfo, toBytes(supplierID)) if err != nil { return nil, err From 8d62dc710d493a1ff0223d7fac87ae362cc1f8e4 Mon Sep 17 00:00:00 2001 From: phuanbui Date: Mon, 29 Aug 2022 14:25:12 +0700 Subject: [PATCH 11/31] fix get supplier --- client/supplier.go | 25 +++++++++++++++++++++++-- model/supplier_request.go | 6 +++++- model/supplier_response.go | 8 ++++++++ subject/supplier.go | 6 ++++-- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/client/supplier.go b/client/supplier.go index 01da757..08eb222 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -17,8 +17,8 @@ func GetSupplier() Supplier { return Supplier{} } -func (s Supplier) GetSupplierInfo(supplierID model.GetSupplierRequest) (*model.ResponseSupplierInfo, error) { - msg, err := natsio.GetServer().Request(subject.Supplier.GetSupplierInfo, toBytes(supplierID)) +func (s Supplier) GetListSupplierInfo(p model.GetSupplierRequest) (*model.ResponseSupplierInfo, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.GetListSupplierInfo, toBytes(p)) if err != nil { return nil, err } @@ -37,3 +37,24 @@ func (s Supplier) GetSupplierInfo(supplierID model.GetSupplierRequest) (*model.R return r.Data, nil } + +func (s Supplier) GetSupplierContractBySupplierID(p model.GetSupplierContractRequest) (*model.ResponseSupplierContract, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.GetSupplierContractBySupplierID, toBytes(p)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseSupplierContract `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/supplier_request.go b/model/supplier_request.go index 2fede05..8372569 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -6,5 +6,9 @@ import ( // GetSupplierRequest ... type GetSupplierRequest struct { - ID primitive.ObjectID `json:"_id"` + ListID []primitive.ObjectID `json:"listID"` +} + +type GetSupplierContractRequest struct { + SupplierID primitive.ObjectID `json:"supplierID"` } diff --git a/model/supplier_response.go b/model/supplier_response.go index de2f579..da33a9f 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -5,3 +5,11 @@ type ResponseSupplierInfo struct { ID string `json:"id"` Name string `json:"name"` } + +// ResponseSupplierContract ... +type ResponseSupplierContract struct { + ID string `json:"id"` + Supplier string `json:"supplier"` + Name string `json:"name"` + Status string `json:"status"` +} diff --git a/subject/supplier.go b/subject/supplier.go index 4b4cf52..b2505cf 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -7,7 +7,9 @@ func getSupplierValue(val string) string { } var Supplier = struct { - GetSupplierInfo string + GetListSupplierInfo string + GetSupplierContractBySupplierID string }{ - GetSupplierInfo: getSupplierValue("get_supplier_info"), + GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), + GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), } From 8dcc6504b9406124e5191cce89dc29e2e7436d53 Mon Sep 17 00:00:00 2001 From: phuanbui Date: Mon, 29 Aug 2022 14:37:45 +0700 Subject: [PATCH 12/31] change reponse get supplier --- client/supplier.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/supplier.go b/client/supplier.go index 08eb222..5b4881a 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -17,15 +17,15 @@ func GetSupplier() Supplier { return Supplier{} } -func (s Supplier) GetListSupplierInfo(p model.GetSupplierRequest) (*model.ResponseSupplierInfo, error) { +func (s Supplier) GetListSupplierInfo(p model.GetSupplierRequest) ([]*model.ResponseSupplierInfo, error) { msg, err := natsio.GetServer().Request(subject.Supplier.GetListSupplierInfo, toBytes(p)) if err != nil { return nil, err } var r struct { - Data *model.ResponseSupplierInfo `json:"data"` - Error string `json:"error"` + Data []*model.ResponseSupplierInfo `json:"data"` + Error string `json:"error"` } if err := json.Unmarshal(msg.Data, &r); err != nil { From 43aa67fa2e6ccd6dbb3a8f4ea9631d21c78bc568 Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 29 Aug 2022 15:55:17 +0700 Subject: [PATCH 13/31] update GC --- model/order_request.go | 9 +++++---- model/warehouse_request.go | 6 ++++++ model/warehouse_response.go | 8 ++++++++ subject/communication.go | 12 ++++-------- subject/order.go | 6 ++---- subject/warehouse.go | 6 ++++++ 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/model/order_request.go b/model/order_request.go index da9d4fe..f8dfde0 100644 --- a/model/order_request.go +++ b/model/order_request.go @@ -2,10 +2,11 @@ package model // OrderUpdateORStatus ... type OrderUpdateORStatus struct { - OrderCode string `json:"orderCode"` - ORCode string `json:"orCode"` - Status string `json:"status"` - Reason string `json:"reason"` + OrderCode string `json:"orderCode"` + ORCode string `json:"orCode"` + Status string `json:"status"` + DeliveryStatus string `json:"deliveryStatus"` + Reason string `json:"reason"` } // OrderCancelDelivery ... diff --git a/model/warehouse_request.go b/model/warehouse_request.go index 51bc667..f63b135 100644 --- a/model/warehouse_request.go +++ b/model/warehouse_request.go @@ -63,3 +63,9 @@ type CancelOutboundRequest struct { ORCode string `json:"orCode"` Note string `json:"note"` } + +// SyncORStatusRequest ... +type SyncORStatusRequest struct { + ORCode string `json:"orCode"` + OrderCode string `json:"orderCode"` +} diff --git a/model/warehouse_response.go b/model/warehouse_response.go index 493a921..cb78ae0 100644 --- a/model/warehouse_response.go +++ b/model/warehouse_response.go @@ -59,3 +59,11 @@ type WarehousePartner struct { Enabled bool `json:"enabled"` Authentication string `json:"authentication"` } + +// SyncORStatusResponse ... +type SyncORStatusResponse struct { + ORCode string `json:"orCode"` + OrderCode string `json:"orderCode"` + Status string `json:"status"` + DeliveryStatus string `json:"deliveryStatus"` +} diff --git a/subject/communication.go b/subject/communication.go index bcbbe31..80926f2 100644 --- a/subject/communication.go +++ b/subject/communication.go @@ -7,13 +7,9 @@ func getCommunicationValue(val string) string { } var Communication = struct { - RequestHTTP string - ResponseHTTP string - WebhookTNC string - WebhookGlobalCare string + RequestHTTP string + ResponseHTTP string }{ - RequestHTTP: getCommunicationValue("request_http"), - ResponseHTTP: getCommunicationValue("response_http"), - WebhookTNC: getCommunicationValue("webhook_tnc"), - WebhookGlobalCare: getCommunicationValue("webhook_global_care"), + RequestHTTP: getCommunicationValue("request_http"), + ResponseHTTP: getCommunicationValue("response_http"), } diff --git a/subject/order.go b/subject/order.go index 846cee5..309f76f 100644 --- a/subject/order.go +++ b/subject/order.go @@ -7,10 +7,8 @@ func getOrderValue(val string) string { } var Order = struct { - UpdateORStatus string - CancelDelivery string - WebhookTNC string - WebhookGlobalCare string + UpdateORStatus string + CancelDelivery string }{ UpdateORStatus: getOrderValue("update_outbound_request_status"), CancelDelivery: getOrderValue("cancel_delivery"), diff --git a/subject/warehouse.go b/subject/warehouse.go index b0801b9..b6e5878 100644 --- a/subject/warehouse.go +++ b/subject/warehouse.go @@ -11,9 +11,15 @@ var Warehouse = struct { UpdateOutboundRequestLogistic string CancelOutboundRequest string GetConfiguration string + SyncORStatus string + WebhookTNC string + WebhookGlobalCare string }{ 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"), } From 05103803ffc7b55fe640b71a63844e73b00a373b Mon Sep 17 00:00:00 2001 From: phuanbui Date: Mon, 29 Aug 2022 17:54:50 +0700 Subject: [PATCH 14/31] add field code --- model/location_response.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/model/location_response.go b/model/location_response.go index 82866ec..f383d12 100644 --- a/model/location_response.go +++ b/model/location_response.go @@ -10,16 +10,19 @@ type ResponseLocationAddress struct { type LocationProvince struct { ID string `json:"id"` Name string `json:"name"` + Code string `json:"code"` } // LocationDistrict ... type LocationDistrict struct { ID string `json:"id"` Name string `json:"name"` + Code string `json:"code"` } // LocationWard ... type LocationWard struct { ID string `json:"id"` Name string `json:"name"` + Code string `json:"code"` } From 21aa37507aae3b88c04e7e154fe0ef453b00e290 Mon Sep 17 00:00:00 2001 From: phuanbui Date: Mon, 29 Aug 2022 18:07:58 +0700 Subject: [PATCH 15/31] edit type field code --- model/location_response.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/model/location_response.go b/model/location_response.go index f383d12..436d1f7 100644 --- a/model/location_response.go +++ b/model/location_response.go @@ -10,19 +10,19 @@ type ResponseLocationAddress struct { type LocationProvince struct { ID string `json:"id"` Name string `json:"name"` - Code string `json:"code"` + Code int `json:"code"` } // LocationDistrict ... type LocationDistrict struct { ID string `json:"id"` Name string `json:"name"` - Code string `json:"code"` + Code int `json:"code"` } // LocationWard ... type LocationWard struct { ID string `json:"id"` Name string `json:"name"` - Code string `json:"code"` + Code int `json:"code"` } From 4bf17d74fa22edef9af05bd8496b5eadb985c412 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Tue, 30 Aug 2022 11:03:02 +0700 Subject: [PATCH 16/31] [Update] Add dao request warehouse --- client/communication.go | 27 +++++ client/location.go | 38 ++++++++ client/order.go | 52 ++++++++++ client/supplier.go | 60 ++++++++++++ client/util.go | 21 ++++ client/warehouse.go | 168 ++++++++++++++++++++++++++++++++ go.mod | 1 + go.sum | 37 ++++++- json_encoder.go | 33 +++++++ model/common_request.go | 17 ++++ model/common_response.go | 18 ++++ model/communication_request.go | 17 ++++ model/communication_response.go | 25 +++++ model/location_request.go | 8 ++ model/location_response.go | 28 ++++++ model/order_request.go | 14 +++ model/supplier_request.go | 14 +++ model/supplier_response.go | 15 +++ model/warehouse_request.go | 51 ++++++++++ model/warehouse_response.go | 107 ++++++++++++++++++++ natsio.go | 3 +- server_reqres.go | 11 +++ subject/communication.go | 19 ++++ subject/config.go | 15 +++ subject/location.go | 13 +++ subject/order.go | 17 ++++ subject/supplier.go | 15 +++ subject/warehouse.go | 27 +++++ 28 files changed, 864 insertions(+), 7 deletions(-) create mode 100644 client/communication.go create mode 100644 client/location.go create mode 100644 client/order.go create mode 100644 client/supplier.go create mode 100644 client/util.go create mode 100644 client/warehouse.go create mode 100644 json_encoder.go create mode 100644 model/common_request.go create mode 100644 model/common_response.go create mode 100644 model/communication_request.go create mode 100644 model/communication_response.go create mode 100644 model/location_request.go create mode 100644 model/location_response.go create mode 100644 model/order_request.go create mode 100644 model/supplier_request.go create mode 100644 model/supplier_response.go create mode 100644 model/warehouse_request.go create mode 100644 model/warehouse_response.go create mode 100644 subject/communication.go create mode 100644 subject/config.go create mode 100644 subject/location.go create mode 100644 subject/order.go create mode 100644 subject/supplier.go create mode 100644 subject/warehouse.go diff --git a/client/communication.go b/client/communication.go new file mode 100644 index 0000000..6dd94cb --- /dev/null +++ b/client/communication.go @@ -0,0 +1,27 @@ +package client + +import ( + "encoding/json" + + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" +) + +// Communication ... +type Communication struct{} + +// GetCommunication ... +func GetCommunication() Communication { + return Communication{} +} + +// RequestHttp ... +func (c Communication) RequestHttp(p model.CommunicationRequestHttp) (r *model.CommunicationHttpResponse, err error) { + msg, err := natsio.GetServer().Request(subject.Communication.RequestHTTP, toBytes(p)) + if err != nil { + return nil, err + } + err = json.Unmarshal(msg.Data, &r) + return r, err +} diff --git a/client/location.go b/client/location.go new file mode 100644 index 0000000..7fc3474 --- /dev/null +++ b/client/location.go @@ -0,0 +1,38 @@ +package client + +import ( + "encoding/json" + "errors" + + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" +) + +// Location ... +type Location struct{} + +// GetLocation ... +func GetLocation() Location { + return Location{} +} + +func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*model.ResponseLocationAddress, error) { + msg, err := natsio.GetServer().Request(subject.Location.GetLocationByCode, toBytes(payload)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseLocationAddress `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/client/order.go b/client/order.go new file mode 100644 index 0000000..4379747 --- /dev/null +++ b/client/order.go @@ -0,0 +1,52 @@ +package client + +import ( + "encoding/json" + "errors" + + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" +) + +// Order ... +type Order struct{} + +// GetOrder ... +func GetOrder() Order { + return Order{} +} + +// UpdateORStatus ... +func (o Order) UpdateORStatus(p model.OrderUpdateORStatus) error { + msg, err := natsio.GetServer().Request(subject.Order.UpdateORStatus, toBytes(p)) + if err != nil { + return err + } + var r struct { + Error string `json:"error"` + } + if err = json.Unmarshal(msg.Data, &r); err != nil { + return err + } + if r.Error != "" { + return errors.New(r.Error) + } + return nil +} + +// CancelDelivery ... +func (o Order) CancelDelivery(p model.OrderCancelDelivery) error { + msg, err := natsio.GetServer().Request(subject.Order.CancelDelivery, 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/client/supplier.go b/client/supplier.go new file mode 100644 index 0000000..5b4881a --- /dev/null +++ b/client/supplier.go @@ -0,0 +1,60 @@ +package client + +import ( + "encoding/json" + "errors" + + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" +) + +// Supplier ... +type Supplier struct{} + +// GetSupplier ... +func GetSupplier() Supplier { + return Supplier{} +} + +func (s Supplier) GetListSupplierInfo(p model.GetSupplierRequest) ([]*model.ResponseSupplierInfo, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.GetListSupplierInfo, toBytes(p)) + if err != nil { + return nil, err + } + + var r struct { + Data []*model.ResponseSupplierInfo `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 +} + +func (s Supplier) GetSupplierContractBySupplierID(p model.GetSupplierContractRequest) (*model.ResponseSupplierContract, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.GetSupplierContractBySupplierID, toBytes(p)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseSupplierContract `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/client/util.go b/client/util.go new file mode 100644 index 0000000..7676610 --- /dev/null +++ b/client/util.go @@ -0,0 +1,21 @@ +package client + +import ( + "encoding/json" + "go.mongodb.org/mongo-driver/bson" + "log" +) + +func toBytes(data interface{}) []byte { + b, err := json.Marshal(data) + if err != nil { + log.Printf("natsio/client.toBytes: marshal_json %v", err) + } + return b +} + +// bsonToBytes ... +func bsonToBytes(data interface{}) []byte { + b, _ := bson.Marshal(data) + return b +} diff --git a/client/warehouse.go b/client/warehouse.go new file mode 100644 index 0000000..5341fb0 --- /dev/null +++ b/client/warehouse.go @@ -0,0 +1,168 @@ +package client + +import ( + "encoding/json" + "errors" + + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" +) + +// Warehouse ... +type Warehouse struct{} + +// GetWarehouse ... +func GetWarehouse() Warehouse { + return Warehouse{} +} + +// DistinctWithField ... +func (w Warehouse) DistinctWithField(p model.FindWithCondition) ([]interface{}, error) { + msg, err := natsio.GetServer().Request(subject.Warehouse.Distinct, bsonToBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data []interface{} `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 +} + +// FindOneByCondition ... +func (w Warehouse) FindOneByCondition(p model.FindWithCondition) (*model.WarehouseNatsResponse, error) { + msg, err := natsio.GetServer().Request(subject.Warehouse.FindOne, bsonToBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data *model.WarehouseNatsResponse `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 +} + +// CountByCondition ... +func (w Warehouse) CountByCondition(p model.FindWithCondition) (int64, error) { + msg, err := natsio.GetServer().Request(subject.Warehouse.Count, bsonToBytes(p)) + if err != nil { + return 0, err + } + var r struct { + Data int64 `json:"data"` + Error string `json:"error"` + } + if err = json.Unmarshal(msg.Data, &r); err != nil { + return 0, err + } + if r.Error != "" { + return 0, errors.New(r.Error) + } + return r.Data, nil +} + +// FindByCondition ... +func (w Warehouse) FindByCondition(p model.FindWithCondition) ([]*model.WarehouseNatsResponse, error) { + msg, err := natsio.GetServer().Request(subject.Warehouse.FindByCondition, bsonToBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data []*model.WarehouseNatsResponse `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 +} + +// CreateOutboundRequest ... +func (w Warehouse) CreateOutboundRequest(p model.OutboundRequestPayload) (*model.OutboundRequestResponse, error) { + msg, err := natsio.GetServer().Request(subject.Warehouse.CreateOutboundRequest, toBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data *model.OutboundRequestResponse `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 +} + +// UpdateOutboundRequestLogisticInfo ... +func (w Warehouse) UpdateOutboundRequestLogisticInfo(p model.UpdateOutboundRequestLogisticInfoPayload) error { + msg, err := natsio.GetServer().Request(subject.Warehouse.UpdateOutboundRequestLogistic, toBytes(p)) + if err != nil { + return err + } + var r struct { + Error string `json:"error"` + } + if err = json.Unmarshal(msg.Data, &r); err != nil { + return err + } + if r.Error != "" { + return errors.New(r.Error) + } + return nil +} + +// CancelOutboundRequest ... +func (w Warehouse) CancelOutboundRequest(p model.CancelOutboundRequest) error { + msg, err := natsio.GetServer().Request(subject.Warehouse.CancelOutboundRequest, toBytes(p)) + if err != nil { + return err + } + var r struct { + Error string `json:"error"` + } + if err = json.Unmarshal(msg.Data, &r); err != nil { + return err + } + if r.Error != "" { + return errors.New(r.Error) + } + return nil +} + +// GetConfigByWarehouseID ... +func (w Warehouse) GetConfigByWarehouseID(warehouseID string) (*model.WarehouseConfiguration, error) { + msg, err := natsio.GetServer().Request(subject.Warehouse.GetConfiguration, toBytes(warehouseID)) + if err != nil { + return nil, err + } + var r struct { + Data *model.WarehouseConfiguration `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/go.mod b/go.mod index ef3b649..8c1bbab 100644 --- a/go.mod +++ b/go.mod @@ -8,5 +8,6 @@ require ( github.com/nats-io/nats-server/v2 v2.6.1 // indirect github.com/nats-io/nats.go v1.13.0 github.com/thoas/go-funk v0.9.1 + go.mongodb.org/mongo-driver v1.10.1 google.golang.org/protobuf v1.27.1 // indirect ) diff --git a/go.sum b/go.sum index a4b26ff..f3e58d6 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,6 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= @@ -9,17 +10,25 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s= github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= +github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= +github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0= github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/nats-io/jwt v1.2.2 h1:w3GMTO969dFg+UOKTmmyuu7IGdusK+7Ytlt//OYH/uU= github.com/nats-io/jwt v1.2.2/go.mod h1:/xX356yQA6LuXI9xWW7mZNpxgF2mBmGecH+Fj34sP5Q= github.com/nats-io/jwt/v2 v2.0.3 h1:i/O6cmIsjpcQyWDYNcq2JyZ3/VTF8SJ4JWluI5OhpvI= @@ -34,29 +43,44 @@ github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8= github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M= github.com/thoas/go-funk v0.9.1/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= +github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= +go.mongodb.org/mongo-driver v1.10.1 h1:NujsPveKwHaWuKUer/ceo9DzEe7HIj1SlJ6uvXZG0S4= +go.mongodb.org/mongo-driver v1.10.1/go.mod h1:z4XpeoU6w+9Vht+jAFyLgVrD+jGSQQe0+CBWFHNiHt8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -72,5 +96,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/json_encoder.go b/json_encoder.go new file mode 100644 index 0000000..af13573 --- /dev/null +++ b/json_encoder.go @@ -0,0 +1,33 @@ +package natsio + +import ( + "log" + + "github.com/nats-io/nats.go" +) + +// JSONEncoder ... +type JSONEncoder struct { + encConn *nats.EncodedConn +} + +// Subscribe ... +func (e JSONEncoder) Subscribe(subject string, cb nats.Handler) (*nats.Subscription, error) { + sub, err := e.encConn.Subscribe(subject, cb) + if err != nil { + log.Printf("natsio.JSONEncoder.Subscribe err: %v\n", err) + } else { + log.Printf("natsio.JSONEncoder - subscribed to subject %s successfully\n", subject) + } + return sub, err +} + +// Publish ... +func (e JSONEncoder) Publish(reply string, data interface{}) error { + return e.encConn.Publish(reply, data) +} + +// Request ... +func (e JSONEncoder) Request(subject string, data interface{}, res interface{}) error { + return e.encConn.Request(subject, data, res, requestTimeout) +} diff --git a/model/common_request.go b/model/common_request.go new file mode 100644 index 0000000..4d6a719 --- /dev/null +++ b/model/common_request.go @@ -0,0 +1,17 @@ +package model + +import "go.mongodb.org/mongo-driver/mongo/options" + +type FindWithCondition struct { + Conditions interface{} `json:"conditions"` + Opts []*options.FindOptions `json:"opts"` +} + +type FindOneCondition struct { + Conditions interface{} `json:"conditions"` +} + +type DistinctWithField struct { + Conditions interface{} `json:"conditions"` + Filed string `json:"filed"` +} diff --git a/model/common_response.go b/model/common_response.go new file mode 100644 index 0000000..2d2aba8 --- /dev/null +++ b/model/common_response.go @@ -0,0 +1,18 @@ +package model + +import "encoding/json" + +// CommonResponseData ... +type CommonResponseData struct { + Data interface{} `json:"data"` + Error string `json:"error"` +} + +// ParseData ... +func (c CommonResponseData) ParseData(resultPointer interface{}) error { + b, err := json.Marshal(c.Data) + if err != nil { + return err + } + return json.Unmarshal(b, resultPointer) +} diff --git a/model/communication_request.go b/model/communication_request.go new file mode 100644 index 0000000..eb64ef2 --- /dev/null +++ b/model/communication_request.go @@ -0,0 +1,17 @@ +package model + +// CommunicationRequestHttp ... +type CommunicationRequestHttp struct { + ResponseImmediately bool `json:"responseImmediately"` + Authentication string `json:"authentication"` + Payload HttpRequest `json:"payload"` +} + +// HttpRequest ... +type HttpRequest struct { + URL string `json:"url"` + Method string `json:"method"` + Data string `json:"data"` + Header map[string]string `json:"header"` + Query map[string]string `json:"query"` +} diff --git a/model/communication_response.go b/model/communication_response.go new file mode 100644 index 0000000..f57e176 --- /dev/null +++ b/model/communication_response.go @@ -0,0 +1,25 @@ +package model + +import "encoding/json" + +// CommunicationHttpResponse ... +type CommunicationHttpResponse struct { + Response *HttpResponse `json:"response"` + Error bool `json:"error"` + Message string `json:"message"` + RequestID string `json:"requestId"` +} + +// ParseResponseData ... +func (r *CommunicationHttpResponse) ParseResponseData(result interface{}) error { + if r.Response == nil { + return nil + } + return json.Unmarshal([]byte(r.Response.Body), result) +} + +// HttpResponse ... +type HttpResponse struct { + Body string `json:"body"` + StatusCode int `json:"statusCode"` +} diff --git a/model/location_request.go b/model/location_request.go new file mode 100644 index 0000000..e6781ca --- /dev/null +++ b/model/location_request.go @@ -0,0 +1,8 @@ +package model + +// LocationRequestPayload ... +type LocationRequestPayload struct { + Province int `json:"province"` + District int `json:"district"` + Ward int `json:"ward"` +} diff --git a/model/location_response.go b/model/location_response.go new file mode 100644 index 0000000..436d1f7 --- /dev/null +++ b/model/location_response.go @@ -0,0 +1,28 @@ +package model + +type ResponseLocationAddress struct { + Province LocationProvince `json:"province"` + District LocationDistrict `json:"district"` + Ward LocationWard `json:"ward"` +} + +// LocationProvince ... +type LocationProvince struct { + ID string `json:"id"` + Name string `json:"name"` + Code int `json:"code"` +} + +// LocationDistrict ... +type LocationDistrict struct { + ID string `json:"id"` + Name string `json:"name"` + Code int `json:"code"` +} + +// LocationWard ... +type LocationWard struct { + ID string `json:"id"` + Name string `json:"name"` + Code int `json:"code"` +} diff --git a/model/order_request.go b/model/order_request.go new file mode 100644 index 0000000..da9d4fe --- /dev/null +++ b/model/order_request.go @@ -0,0 +1,14 @@ +package model + +// OrderUpdateORStatus ... +type OrderUpdateORStatus struct { + OrderCode string `json:"orderCode"` + ORCode string `json:"orCode"` + Status string `json:"status"` + Reason string `json:"reason"` +} + +// OrderCancelDelivery ... +type OrderCancelDelivery struct { + OrderID string `json:"orderId"` +} diff --git a/model/supplier_request.go b/model/supplier_request.go new file mode 100644 index 0000000..8372569 --- /dev/null +++ b/model/supplier_request.go @@ -0,0 +1,14 @@ +package model + +import ( + "go.mongodb.org/mongo-driver/bson/primitive" +) + +// GetSupplierRequest ... +type GetSupplierRequest struct { + ListID []primitive.ObjectID `json:"listID"` +} + +type GetSupplierContractRequest struct { + SupplierID primitive.ObjectID `json:"supplierID"` +} diff --git a/model/supplier_response.go b/model/supplier_response.go new file mode 100644 index 0000000..da33a9f --- /dev/null +++ b/model/supplier_response.go @@ -0,0 +1,15 @@ +package model + +// ResponseSupplierInfo ... +type ResponseSupplierInfo struct { + ID string `json:"id"` + Name string `json:"name"` +} + +// ResponseSupplierContract ... +type ResponseSupplierContract struct { + ID string `json:"id"` + Supplier string `json:"supplier"` + Name string `json:"name"` + Status string `json:"status"` +} diff --git a/model/warehouse_request.go b/model/warehouse_request.go new file mode 100644 index 0000000..5612532 --- /dev/null +++ b/model/warehouse_request.go @@ -0,0 +1,51 @@ +package model + +// OutboundRequestPayload ... +type OutboundRequestPayload struct { + OrderID string `json:"orderId"` + OrderCode string `json:"orderCode"` + TrackingCode string `json:"trackingCode"` + WarehouseID string `json:"warehouseId"` + SupplierID string `json:"supplierId"` + Note string `json:"note"` + CODAmount float64 `json:"codAmount"` + TPLCode string `json:"tplCode"` + Customer CustomerInfo `json:"customer"` + Items []OutboundRequestItem `json:"items"` +} + +// OutboundRequestItem ... +type OutboundRequestItem struct { + SupplierSKU string `json:"supplierSKU"` + Quantity int64 `json:"quantity"` + UnitCode string `json:"unitCode"` +} + +// CustomerInfo ... +type CustomerInfo struct { + Name string `json:"name"` + PhoneNumber string `json:"phoneNumber"` + Address AddressDetail `json:"address"` +} + +// AddressDetail ... +type AddressDetail struct { + Address string `json:"address"` + FullAddress string `json:"fullAddress"` + ProvinceCode int `json:"provinceCode"` + DistrictCode int `json:"districtCode"` + WardCode int `json:"wardCode"` +} + +// UpdateOutboundRequestLogisticInfoPayload ... +type UpdateOutboundRequestLogisticInfoPayload struct { + ShippingLabel string `json:"shippingLabel"` + TrackingCode string `json:"trackingCode"` + ORCode string `json:"orCode"` +} + +// CancelOutboundRequest ... +type CancelOutboundRequest struct { + ORCode string `json:"orCode"` + Note string `json:"note"` +} diff --git a/model/warehouse_response.go b/model/warehouse_response.go new file mode 100644 index 0000000..9010be8 --- /dev/null +++ b/model/warehouse_response.go @@ -0,0 +1,107 @@ +package model + +import "time" + +// OutboundRequestResponse ... +type OutboundRequestResponse struct { + // System code + OrderCode string `json:"orderCode"` + TrackingCode string `json:"trackingCode"` + ID string `json:"id"` // OR id + + // Partner response + ORCode string `json:"orCode"` + RequestID string `json:"requestId"` + Status string `json:"status"` + Reason string `json:"reason"` +} + +// WarehouseConfiguration ... +type WarehouseConfiguration struct { + Warehouse string `json:"warehouse"` + DoesSupportSellyExpress bool `json:"doesSupportSellyExpress"` + Supplier WarehouseSupplier `json:"supplier"` + Order WarehouseOrder `json:"order"` + Partner WarehousePartner `json:"partner"` + Delivery WarehouseDelivery `json:"delivery"` +} + +// WarehouseSupplier ... +type WarehouseSupplier struct { + CanAutoSendMail bool `json:"canAutoSendMail"` + InvoiceDeliveryMethod string `json:"invoiceDeliveryMethod"` +} + +// WarehouseOrder ... +type WarehouseOrder struct { + MinimumValue float64 `json:"minimumValue"` + PaymentMethod WarehousePaymentMethod `json:"paymentMethod"` + IsLimitNumberOfPurchases bool `json:"isLimitNumberOfPurchases"` + LimitNumberOfPurchases int64 `json:"limitNumberOfPurchases"` +} + +// WarehousePaymentMethod ... +type WarehousePaymentMethod struct { + Cod bool `json:"cod"` + BankTransfer bool `json:"bankTransfer"` +} + +// WarehouseDelivery ... +type WarehouseDelivery struct { + DeliveryMethods []string `json:"deliveryMethods"` + PriorityServiceCodes []string `json:"priorityServiceCodes"` + EnabledSources []int `json:"enabledSources"` + Types []string `json:"types"` +} + +// WarehousePartner ... +type WarehousePartner struct { + IdentityCode string `json:"identityCode"` + Code string `json:"code"` + Enabled bool `json:"enabled"` + Authentication string `json:"authentication"` +} + +// ResponseWarehouseContact ... +type ResponseWarehouseContact struct { + Name string `json:"name"` + Phone string `json:"phone"` + Address string `json:"address"` + Email string `json:"email"` +} + +// ResponseWarehouseLocation ... +type ResponseWarehouseLocation struct { + Province CommonLocation `json:"province"` + District CommonLocation `json:"district"` + Ward CommonLocation `json:"ward"` + Address string `json:"address"` + LocationCoordinates ResponseLatLng `json:"locationCoordinates"` +} + +type CommonLocation struct { + ID string `json:"id"` + Name string `json:"name"` + Code int `json:"code"` +} + +// ResponseLatLng ... +type ResponseLatLng struct { + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` +} + +// WarehouseNatsResponse ... +type WarehouseNatsResponse struct { + ID string `json:"_id"` + Name string `json:"name"` + SearchString string `json:"searchString"` + Slug string `json:"slug"` + Status string `json:"status"` + Supplier WarehouseSupplier `json:"supplier"` + Contact ResponseWarehouseContact `json:"contact"` + Location ResponseWarehouseLocation `json:"location"` + Configurations WarehouseConfiguration `json:"configurations"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` +} diff --git a/natsio.go b/natsio.go index 5ccc45d..0c2bca7 100644 --- a/natsio.go +++ b/natsio.go @@ -3,7 +3,6 @@ package natsio import ( "errors" "fmt" - "github.com/logrusorgru/aurora" "github.com/nats-io/nats.go" ) @@ -49,7 +48,7 @@ func Connect(cfg Config) error { return errors.New(msg) } - fmt.Println(aurora.Green("*** CONNECTED TO NATS: " + cfg.URL)) + fmt.Printf("⚡️[natsio]: connected to %s \n", cfg.URL) // Set client natsServer.instance = nc diff --git a/server_reqres.go b/server_reqres.go index cb50938..841f9ef 100644 --- a/server_reqres.go +++ b/server_reqres.go @@ -3,6 +3,7 @@ package natsio import ( "errors" "fmt" + "log" "time" "github.com/nats-io/nats.go" @@ -34,3 +35,13 @@ func (sv Server) Subscribe(subject string, cb nats.MsgHandler) (*nats.Subscripti } return sub, nil } + +// NewJSONEncodedConn ... +func (sv Server) NewJSONEncodedConn() (*JSONEncoder, error) { + enc, err := nats.NewEncodedConn(sv.instance, nats.JSON_ENCODER) + if err != nil { + log.Printf("natsio.NewJSONEncodedConn: err %v\n", err) + return nil, err + } + return &JSONEncoder{encConn: enc}, nil +} diff --git a/subject/communication.go b/subject/communication.go new file mode 100644 index 0000000..bcbbe31 --- /dev/null +++ b/subject/communication.go @@ -0,0 +1,19 @@ +package subject + +import "fmt" + +func getCommunicationValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Communication, val) +} + +var Communication = struct { + RequestHTTP string + ResponseHTTP string + WebhookTNC string + WebhookGlobalCare string +}{ + RequestHTTP: getCommunicationValue("request_http"), + ResponseHTTP: getCommunicationValue("response_http"), + WebhookTNC: getCommunicationValue("webhook_tnc"), + WebhookGlobalCare: getCommunicationValue("webhook_global_care"), +} diff --git a/subject/config.go b/subject/config.go new file mode 100644 index 0000000..dfeea56 --- /dev/null +++ b/subject/config.go @@ -0,0 +1,15 @@ +package subject + +var prefixes = struct { + Communication string + Order string + Warehouse string + Location string + Supplier string +}{ + Communication: "communication", + Order: "order", + Warehouse: "warehouse", + Location: "location", + Supplier: "supplier", +} diff --git a/subject/location.go b/subject/location.go new file mode 100644 index 0000000..1989df3 --- /dev/null +++ b/subject/location.go @@ -0,0 +1,13 @@ +package subject + +import "fmt" + +func getLocationValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Location, val) +} + +var Location = struct { + GetLocationByCode string +}{ + GetLocationByCode: getLocationValue("get_location_warehouse"), +} diff --git a/subject/order.go b/subject/order.go new file mode 100644 index 0000000..846cee5 --- /dev/null +++ b/subject/order.go @@ -0,0 +1,17 @@ +package subject + +import "fmt" + +func getOrderValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Order, val) +} + +var Order = struct { + UpdateORStatus string + CancelDelivery string + WebhookTNC string + WebhookGlobalCare string +}{ + UpdateORStatus: getOrderValue("update_outbound_request_status"), + CancelDelivery: getOrderValue("cancel_delivery"), +} diff --git a/subject/supplier.go b/subject/supplier.go new file mode 100644 index 0000000..b2505cf --- /dev/null +++ b/subject/supplier.go @@ -0,0 +1,15 @@ +package subject + +import "fmt" + +func getSupplierValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Supplier, val) +} + +var Supplier = struct { + GetListSupplierInfo string + GetSupplierContractBySupplierID string +}{ + GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), + GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), +} diff --git a/subject/warehouse.go b/subject/warehouse.go new file mode 100644 index 0000000..d4f8c53 --- /dev/null +++ b/subject/warehouse.go @@ -0,0 +1,27 @@ +package subject + +import "fmt" + +func getWarehouseValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Warehouse, val) +} + +var Warehouse = struct { + CreateOutboundRequest string + UpdateOutboundRequestLogistic string + CancelOutboundRequest string + GetConfiguration string + FindOne string + FindByCondition string + Distinct string + Count string +}{ + CreateOutboundRequest: getWarehouseValue("create_outbound_request"), + UpdateOutboundRequestLogistic: getWarehouseValue("update_outbound_request_logistic_info"), + CancelOutboundRequest: getWarehouseValue("cancel_outbound_request"), + GetConfiguration: getWarehouseValue("get_configuration"), + FindOne: getWarehouseValue("find_one"), + FindByCondition: getWarehouseValue("find_all_by_condition"), + Distinct: getWarehouseValue("distinct"), + Count: getWarehouseValue("count"), +} From 868c3166ce855b94888c4921a4fe898ddbe15dcf Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Tue, 30 Aug 2022 14:03:49 +0700 Subject: [PATCH 17/31] [Update] Add dao request warehouse --- client/warehouse.go | 76 --------------------------------- client/warehouse_dao.go | 85 +++++++++++++++++++++++++++++++++++++ model/warehouse_response.go | 2 +- 3 files changed, 86 insertions(+), 77 deletions(-) create mode 100644 client/warehouse_dao.go diff --git a/client/warehouse.go b/client/warehouse.go index 5341fb0..ed19faf 100644 --- a/client/warehouse.go +++ b/client/warehouse.go @@ -17,82 +17,6 @@ func GetWarehouse() Warehouse { return Warehouse{} } -// DistinctWithField ... -func (w Warehouse) DistinctWithField(p model.FindWithCondition) ([]interface{}, error) { - msg, err := natsio.GetServer().Request(subject.Warehouse.Distinct, bsonToBytes(p)) - if err != nil { - return nil, err - } - var r struct { - Data []interface{} `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 -} - -// FindOneByCondition ... -func (w Warehouse) FindOneByCondition(p model.FindWithCondition) (*model.WarehouseNatsResponse, error) { - msg, err := natsio.GetServer().Request(subject.Warehouse.FindOne, bsonToBytes(p)) - if err != nil { - return nil, err - } - var r struct { - Data *model.WarehouseNatsResponse `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 -} - -// CountByCondition ... -func (w Warehouse) CountByCondition(p model.FindWithCondition) (int64, error) { - msg, err := natsio.GetServer().Request(subject.Warehouse.Count, bsonToBytes(p)) - if err != nil { - return 0, err - } - var r struct { - Data int64 `json:"data"` - Error string `json:"error"` - } - if err = json.Unmarshal(msg.Data, &r); err != nil { - return 0, err - } - if r.Error != "" { - return 0, errors.New(r.Error) - } - return r.Data, nil -} - -// FindByCondition ... -func (w Warehouse) FindByCondition(p model.FindWithCondition) ([]*model.WarehouseNatsResponse, error) { - msg, err := natsio.GetServer().Request(subject.Warehouse.FindByCondition, bsonToBytes(p)) - if err != nil { - return nil, err - } - var r struct { - Data []*model.WarehouseNatsResponse `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 -} - // CreateOutboundRequest ... func (w Warehouse) CreateOutboundRequest(p model.OutboundRequestPayload) (*model.OutboundRequestResponse, error) { msg, err := natsio.GetServer().Request(subject.Warehouse.CreateOutboundRequest, toBytes(p)) diff --git a/client/warehouse_dao.go b/client/warehouse_dao.go new file mode 100644 index 0000000..10f2add --- /dev/null +++ b/client/warehouse_dao.go @@ -0,0 +1,85 @@ +package client + +import ( + "encoding/json" + "errors" + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" +) + +// DistinctWithField ... +func (w Warehouse) DistinctWithField(p model.FindWithCondition) ([]interface{}, error) { + msg, err := natsio.GetServer().Request(subject.Warehouse.Distinct, bsonToBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data []interface{} `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 +} + +// FindOneByCondition ... +func (w Warehouse) FindOneByCondition(p model.FindWithCondition) (*model.WarehouseNatsResponse, error) { + msg, err := natsio.GetServer().Request(subject.Warehouse.FindOne, bsonToBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data *model.WarehouseNatsResponse `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 +} + +// CountByCondition ... +func (w Warehouse) CountByCondition(p model.FindWithCondition) (int64, error) { + msg, err := natsio.GetServer().Request(subject.Warehouse.Count, bsonToBytes(p)) + if err != nil { + return 0, err + } + var r struct { + Data int64 `json:"data"` + Error string `json:"error"` + } + if err = json.Unmarshal(msg.Data, &r); err != nil { + return 0, err + } + if r.Error != "" { + return 0, errors.New(r.Error) + } + return r.Data, nil +} + +// FindByCondition ... +func (w Warehouse) FindByCondition(p model.FindWithCondition) ([]*model.WarehouseNatsResponse, error) { + msg, err := natsio.GetServer().Request(subject.Warehouse.FindByCondition, bsonToBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data []*model.WarehouseNatsResponse `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/warehouse_response.go b/model/warehouse_response.go index 9010be8..e0d35b1 100644 --- a/model/warehouse_response.go +++ b/model/warehouse_response.go @@ -98,7 +98,7 @@ type WarehouseNatsResponse struct { SearchString string `json:"searchString"` Slug string `json:"slug"` Status string `json:"status"` - Supplier WarehouseSupplier `json:"supplier"` + Supplier string `json:"supplier"` Contact ResponseWarehouseContact `json:"contact"` Location ResponseWarehouseLocation `json:"location"` Configurations WarehouseConfiguration `json:"configurations"` From 6a7db08c98f6835ea77d288f1f7ba69fee6013ef Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Tue, 30 Aug 2022 14:44:48 +0700 Subject: [PATCH 18/31] [Update] Add --- client/warehouse_dao.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/warehouse_dao.go b/client/warehouse_dao.go index 10f2add..40c10a4 100644 --- a/client/warehouse_dao.go +++ b/client/warehouse_dao.go @@ -28,7 +28,7 @@ func (w Warehouse) DistinctWithField(p model.FindWithCondition) ([]interface{}, } // FindOneByCondition ... -func (w Warehouse) FindOneByCondition(p model.FindWithCondition) (*model.WarehouseNatsResponse, error) { +func (w Warehouse) FindOneByCondition(p model.FindOneCondition) (*model.WarehouseNatsResponse, error) { msg, err := natsio.GetServer().Request(subject.Warehouse.FindOne, bsonToBytes(p)) if err != nil { return nil, err From 8cdfdcb4e68944b145916738d4a3527b85622416 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Tue, 30 Aug 2022 15:15:11 +0700 Subject: [PATCH 19/31] [Update] Condition dao --- client/warehouse_dao.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/warehouse_dao.go b/client/warehouse_dao.go index 40c10a4..69c2245 100644 --- a/client/warehouse_dao.go +++ b/client/warehouse_dao.go @@ -9,7 +9,7 @@ import ( ) // DistinctWithField ... -func (w Warehouse) DistinctWithField(p model.FindWithCondition) ([]interface{}, error) { +func (w Warehouse) DistinctWithField(p model.DistinctWithField) ([]interface{}, error) { msg, err := natsio.GetServer().Request(subject.Warehouse.Distinct, bsonToBytes(p)) if err != nil { return nil, err From 01c28e1ee3f1b0e17e282d6bcc2210b6c6ba7be1 Mon Sep 17 00:00:00 2001 From: Sinh Date: Tue, 30 Aug 2022 15:55:20 +0700 Subject: [PATCH 20/31] add err log --- server_reqres.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server_reqres.go b/server_reqres.go index 841f9ef..8979ab0 100644 --- a/server_reqres.go +++ b/server_reqres.go @@ -18,7 +18,11 @@ func (sv Server) Request(subject string, payload []byte) (*nats.Msg, error) { if sv.Config.RequestTimeout > 0 { timeout = sv.Config.RequestTimeout } - return sv.instance.Request(subject, payload, timeout) + msg, err := sv.instance.Request(subject, payload, timeout) + if errors.Is(err, nats.ErrNoResponders) { + log.Printf("[NATS SERVER]: request - no responders for subject: %s", subject) + } + return msg, err } // Reply ... From 12afbd81fe117b9ca644544f205402f0dc8e944e Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 31 Aug 2022 10:53:51 +0700 Subject: [PATCH 21/31] add order func --- client/order.go | 16 ++++++++++++++++ model/common_request.go | 5 +++++ model/order_request.go | 7 +++++++ subject/order.go | 10 ++++++---- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/client/order.go b/client/order.go index 4379747..5400f52 100644 --- a/client/order.go +++ b/client/order.go @@ -50,3 +50,19 @@ func (o Order) CancelDelivery(p model.OrderCancelDelivery) error { } return nil } + +// ChangeDeliveryStatus ... +func (o Order) ChangeDeliveryStatus(p model.OrderChangeDeliveryStatus) error { + msg, err := natsio.GetServer().Request(subject.Order.ChangeDeliveryStatus, 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/common_request.go b/model/common_request.go index 4d6a719..0ce5163 100644 --- a/model/common_request.go +++ b/model/common_request.go @@ -15,3 +15,8 @@ type DistinctWithField struct { Conditions interface{} `json:"conditions"` Filed string `json:"filed"` } + +type ActionBy struct { + ID string `json:"id"` + Name string `json:"name"` +} diff --git a/model/order_request.go b/model/order_request.go index f8dfde0..553d870 100644 --- a/model/order_request.go +++ b/model/order_request.go @@ -13,3 +13,10 @@ type OrderUpdateORStatus struct { type OrderCancelDelivery struct { OrderID string `json:"orderId"` } + +// OrderChangeDeliveryStatus ... +type OrderChangeDeliveryStatus struct { + OrderID string `json:"orderId"` + DeliveryStatus string `json:"deliveryStatus"` + ActionBy ActionBy `json:"actionBy"` +} diff --git a/subject/order.go b/subject/order.go index 309f76f..7ba7886 100644 --- a/subject/order.go +++ b/subject/order.go @@ -7,9 +7,11 @@ func getOrderValue(val string) string { } var Order = struct { - UpdateORStatus string - CancelDelivery string + UpdateORStatus string + CancelDelivery string + ChangeDeliveryStatus string }{ - UpdateORStatus: getOrderValue("update_outbound_request_status"), - CancelDelivery: getOrderValue("cancel_delivery"), + UpdateORStatus: getOrderValue("update_outbound_request_status"), + CancelDelivery: getOrderValue("cancel_delivery"), + ChangeDeliveryStatus: getOrderValue("change_delivery_status"), } From 9295a8e13f9181cc4546151114f7e1edb387d4e1 Mon Sep 17 00:00:00 2001 From: nguyenphamquangtue <44862367+nguyenphamquangtue@users.noreply.github.com> Date: Wed, 31 Aug 2022 14:48:24 +0700 Subject: [PATCH 22/31] Intergrate model for supplier (#15) * build nats supplier * build nats supplier * build nats supplier * build nats supplier --- client/supplier.go | 21 +++++++++++++++++++++ model/supplier_request.go | 10 ++++++++++ model/supplier_response.go | 14 ++++++++++++++ subject/supplier.go | 2 ++ 4 files changed, 47 insertions(+) diff --git a/client/supplier.go b/client/supplier.go index 5b4881a..700d714 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -58,3 +58,24 @@ func (s Supplier) GetSupplierContractBySupplierID(p model.GetSupplierContractReq return r.Data, nil } + +func (s Supplier) FindAll(supplierID model.SupplierRequestPayload) (*model.SupplierAll, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.FindAll, toBytes(supplierID)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.SupplierAll `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/supplier_request.go b/model/supplier_request.go index 8372569..04d15d5 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -12,3 +12,13 @@ type GetSupplierRequest struct { type GetSupplierContractRequest struct { SupplierID primitive.ObjectID `json:"supplierID"` } + +// SupplierRequestPayload ... +type SupplierRequestPayload struct { + Limit int + Page int + Keyword string + Status string + PIC string + ContractStatus string +} diff --git a/model/supplier_response.go b/model/supplier_response.go index da33a9f..a87a29e 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -13,3 +13,17 @@ type ResponseSupplierContract struct { Name string `json:"name"` Status string `json:"status"` } + +// SupplierBrief ... +type SupplierBrief struct { + ID string `json:"_id"` + Name string `json:"name"` + Status string `json:"status"` + CreatedAt string `json:"createdAt"` + UpdatedAt string `json:"updatedAt"` +} + +type SupplierAll struct { + Suppliers []SupplierBrief `json:"suppliers"` + Total int64 `json:"total"` +} diff --git a/subject/supplier.go b/subject/supplier.go index b2505cf..17ca8d0 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -9,7 +9,9 @@ func getSupplierValue(val string) string { var Supplier = struct { GetListSupplierInfo string GetSupplierContractBySupplierID string + FindAll string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), + FindAll: getSupplierValue("find_all"), } From e0a4a508a65643b7d859ee4f288608693e64018e Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Wed, 31 Aug 2022 16:51:13 +0700 Subject: [PATCH 23/31] [Update] Action create + update warehouse --- client/warehouse.go | 36 ++++++++++++++++++++++++++++++++++++ subject/warehouse.go | 4 ++++ 2 files changed, 40 insertions(+) diff --git a/client/warehouse.go b/client/warehouse.go index ed19faf..6c04925 100644 --- a/client/warehouse.go +++ b/client/warehouse.go @@ -17,6 +17,42 @@ func GetWarehouse() Warehouse { return Warehouse{} } +// AfterCreateWarehouse ... +func (w Warehouse) AfterCreateWarehouse(p model.WarehouseNatsResponse) error { + msg, err := natsio.GetServer().Request(subject.Warehouse.AfterCreateWarehouse, toBytes(p)) + if err != nil { + return err + } + var r struct { + Error string `json:"error"` + } + if err = json.Unmarshal(msg.Data, &r); err != nil { + return err + } + if r.Error != "" { + return errors.New(r.Error) + } + return nil +} + +// AfterUpdateWarehouse ... +func (w Warehouse) AfterUpdateWarehouse(p model.WarehouseNatsResponse) error { + msg, err := natsio.GetServer().Request(subject.Warehouse.AfterUpdateWarehouse, toBytes(p)) + if err != nil { + return err + } + var r struct { + Error string `json:"error"` + } + if err = json.Unmarshal(msg.Data, &r); err != nil { + return err + } + if r.Error != "" { + return errors.New(r.Error) + } + return nil +} + // CreateOutboundRequest ... func (w Warehouse) CreateOutboundRequest(p model.OutboundRequestPayload) (*model.OutboundRequestResponse, error) { msg, err := natsio.GetServer().Request(subject.Warehouse.CreateOutboundRequest, toBytes(p)) diff --git a/subject/warehouse.go b/subject/warehouse.go index d4f8c53..73c5334 100644 --- a/subject/warehouse.go +++ b/subject/warehouse.go @@ -15,7 +15,11 @@ var Warehouse = struct { FindByCondition string Distinct string Count string + AfterUpdateWarehouse string + AfterCreateWarehouse string }{ + 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"), From e387471efe877d0f9519e2cfdf70c8147a747467 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Wed, 31 Aug 2022 18:06:00 +0700 Subject: [PATCH 24/31] [Update] Add reponse other --- model/warehouse_response.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/model/warehouse_response.go b/model/warehouse_response.go index e0d35b1..b19ade9 100644 --- a/model/warehouse_response.go +++ b/model/warehouse_response.go @@ -24,6 +24,12 @@ type WarehouseConfiguration struct { Order WarehouseOrder `json:"order"` Partner WarehousePartner `json:"partner"` Delivery WarehouseDelivery `json:"delivery"` + Other WarehouseOther `json:"other"` +} + +// WarehouseOther ... +type WarehouseOther struct { + DoesSupportSellyExpress bool `json:"doesSupportSellyExpress"` } // WarehouseSupplier ... From af6e0843b90cdc5b4985837d90d8e62246f0ff88 Mon Sep 17 00:00:00 2001 From: Sinh Date: Tue, 6 Sep 2022 11:09:52 +0700 Subject: [PATCH 25/31] update order OR model --- model/order_request.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/model/order_request.go b/model/order_request.go index 553d870..2bba161 100644 --- a/model/order_request.go +++ b/model/order_request.go @@ -2,11 +2,12 @@ package model // OrderUpdateORStatus ... type OrderUpdateORStatus struct { - OrderCode string `json:"orderCode"` - ORCode string `json:"orCode"` - Status string `json:"status"` - DeliveryStatus string `json:"deliveryStatus"` - Reason string `json:"reason"` + OrderCode string `json:"orderCode"` + ORCode string `json:"orCode"` + Status string `json:"status"` + DeliveryStatus string `json:"deliveryStatus"` + Reason string `json:"reason"` + Data OrderORData `json:"data"` } // OrderCancelDelivery ... @@ -20,3 +21,8 @@ type OrderChangeDeliveryStatus struct { DeliveryStatus string `json:"deliveryStatus"` ActionBy ActionBy `json:"actionBy"` } + +// OrderORData ... +type OrderORData struct { + Link string `json:"link"` +} From 367dc7edd979e79712ffb9cd653fff4bf465dabf Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 7 Sep 2022 12:00:40 +0700 Subject: [PATCH 26/31] 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"), } From 9b40f5f9ba519d08d818ec01e81a67f00557b474 Mon Sep 17 00:00:00 2001 From: phuanbui Date: Wed, 7 Sep 2022 14:01:29 +0700 Subject: [PATCH 27/31] 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"), } From 218123ccfbd1ac6a8233446139c4de4edd8cae8f Mon Sep 17 00:00:00 2001 From: phuanbui Date: Wed, 7 Sep 2022 14:10:23 +0700 Subject: [PATCH 28/31] 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"), } From 6059889551d4ef14608dac1c56f52ae30150f6ee Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Wed, 7 Sep 2022 17:03:29 +0700 Subject: [PATCH 29/31] [Update] WarehouseNatsResponse --- model/warehouse_response.go | 1 + 1 file changed, 1 insertion(+) diff --git a/model/warehouse_response.go b/model/warehouse_response.go index b19ade9..f394770 100644 --- a/model/warehouse_response.go +++ b/model/warehouse_response.go @@ -100,6 +100,7 @@ type ResponseLatLng struct { // WarehouseNatsResponse ... type WarehouseNatsResponse struct { ID string `json:"_id"` + Staff string `json:"staff"` Name string `json:"name"` SearchString string `json:"searchString"` Slug string `json:"slug"` From 943fff292dbdddbfc9e329190130f03463f9bee7 Mon Sep 17 00:00:00 2001 From: Sinh Date: Thu, 8 Sep 2022 14:47:52 +0700 Subject: [PATCH 30/31] add order func --- client/order.go | 16 ++++++++++++++++ model/order_request.go | 5 +++++ subject/order.go | 2 ++ 3 files changed, 23 insertions(+) diff --git a/client/order.go b/client/order.go index 8834495..7d23cee 100644 --- a/client/order.go +++ b/client/order.go @@ -82,3 +82,19 @@ func (o Order) UpdateLogisticInfoFailed(p model.OrderUpdateLogisticInfoFailed) e } return nil } + +// ORNotUpdateStatus ... +func (o Order) ORNotUpdateStatus(p model.OrderORsNotUpdateStatus) error { + msg, err := natsio.GetServer().Request(subject.Order.ORNotUpdateStatus, 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 48bbb79..af4989d 100644 --- a/model/order_request.go +++ b/model/order_request.go @@ -33,3 +33,8 @@ type OrderUpdateLogisticInfoFailed struct { ORCode string `json:"orCode"` Reason string `json:"reason"` } + +// OrderORsNotUpdateStatus ... +type OrderORsNotUpdateStatus struct { + ORCodes []string `json:"orCodes"` +} diff --git a/subject/order.go b/subject/order.go index 40f190e..1452de3 100644 --- a/subject/order.go +++ b/subject/order.go @@ -11,9 +11,11 @@ var Order = struct { CancelDelivery string ChangeDeliveryStatus string UpdateLogisticInfoFailed string + ORNotUpdateStatus string }{ UpdateORStatus: getOrderValue("update_outbound_request_status"), CancelDelivery: getOrderValue("cancel_delivery"), ChangeDeliveryStatus: getOrderValue("change_delivery_status"), UpdateLogisticInfoFailed: getOrderValue("update_logistic_info_failed"), + ORNotUpdateStatus: getOrderValue("outbound_request_not_update_status"), } From 26a116a2a444abffa008f7dd6ad448d791d3cafc Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 12 Sep 2022 10:01:47 +0700 Subject: [PATCH 31/31] add json tag --- model/warehouse_request.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/warehouse_request.go b/model/warehouse_request.go index f63b135..543fc68 100644 --- a/model/warehouse_request.go +++ b/model/warehouse_request.go @@ -12,7 +12,7 @@ type OutboundRequestPayload struct { TPLCode string `json:"tplCode"` Customer CustomerInfo `json:"customer"` Items []OutboundRequestItem `json:"items"` - Insurance *InsuranceOpts + Insurance *InsuranceOpts `json:"insurance"` } // InsuranceOpts ...