From 3458f885ec240e518d55e101a2468128dd457bf9 Mon Sep 17 00:00:00 2001 From: phuanbui Date: Fri, 26 Aug 2022 17:15:49 +0700 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 4/4] 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