From 0a82f40a252b79f9dfaa3d24d73b76973a1aa2b5 Mon Sep 17 00:00:00 2001 From: namhq Date: Mon, 10 Oct 2022 04:05:49 +0000 Subject: [PATCH 1/4] Update 'go.mod' --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ac44201..bd87680 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/Selly-Modules/natsio +module git.selly.red/Selly-Modules/natsio go 1.16 From c11419a3ad3353b5c32da1d47c29ae3f8a0a5e45 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Mon, 10 Oct 2022 11:11:39 +0700 Subject: [PATCH 2/4] [Update] Package --- client/communication.go | 6 +++--- client/location.go | 6 +++--- client/news.go | 6 +++--- client/order.go | 6 +++--- client/seller.go | 6 +++--- client/supplier.go | 6 +++--- client/warehouse.go | 6 +++--- client/warehouse_dao.go | 6 +++--- go.sum | 13 +++++++++++-- 9 files changed, 35 insertions(+), 26 deletions(-) diff --git a/client/communication.go b/client/communication.go index 6dd94cb..1d8254d 100644 --- a/client/communication.go +++ b/client/communication.go @@ -3,9 +3,9 @@ package client import ( "encoding/json" - "github.com/Selly-Modules/natsio" - "github.com/Selly-Modules/natsio/model" - "github.com/Selly-Modules/natsio/subject" + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" ) // Communication ... diff --git a/client/location.go b/client/location.go index 2e8d30e..18be423 100644 --- a/client/location.go +++ b/client/location.go @@ -4,9 +4,9 @@ import ( "encoding/json" "errors" - "github.com/Selly-Modules/natsio" - "github.com/Selly-Modules/natsio/model" - "github.com/Selly-Modules/natsio/subject" + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" ) // Location ... diff --git a/client/news.go b/client/news.go index 6bacf54..d33787a 100644 --- a/client/news.go +++ b/client/news.go @@ -3,9 +3,9 @@ package client import ( "encoding/json" "errors" - "github.com/Selly-Modules/natsio" - "github.com/Selly-Modules/natsio/model" - "github.com/Selly-Modules/natsio/subject" + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" ) // News ... diff --git a/client/order.go b/client/order.go index 7d23cee..2e7f0a3 100644 --- a/client/order.go +++ b/client/order.go @@ -4,9 +4,9 @@ import ( "encoding/json" "errors" - "github.com/Selly-Modules/natsio" - "github.com/Selly-Modules/natsio/model" - "github.com/Selly-Modules/natsio/subject" + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" ) // Order ... diff --git a/client/seller.go b/client/seller.go index 1d06208..30987bd 100644 --- a/client/seller.go +++ b/client/seller.go @@ -4,9 +4,9 @@ import ( "encoding/json" "errors" - "github.com/Selly-Modules/natsio" - "github.com/Selly-Modules/natsio/model" - "github.com/Selly-Modules/natsio/subject" + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" ) // Seller ... diff --git a/client/supplier.go b/client/supplier.go index 700d714..8de78fb 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -4,9 +4,9 @@ import ( "encoding/json" "errors" - "github.com/Selly-Modules/natsio" - "github.com/Selly-Modules/natsio/model" - "github.com/Selly-Modules/natsio/subject" + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" ) // Supplier ... diff --git a/client/warehouse.go b/client/warehouse.go index 5ae07db..944c2cb 100644 --- a/client/warehouse.go +++ b/client/warehouse.go @@ -4,9 +4,9 @@ import ( "encoding/json" "errors" - "github.com/Selly-Modules/natsio" - "github.com/Selly-Modules/natsio/model" - "github.com/Selly-Modules/natsio/subject" + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" ) // Warehouse ... diff --git a/client/warehouse_dao.go b/client/warehouse_dao.go index 69c2245..56c046f 100644 --- a/client/warehouse_dao.go +++ b/client/warehouse_dao.go @@ -3,9 +3,9 @@ package client import ( "encoding/json" "errors" - "github.com/Selly-Modules/natsio" - "github.com/Selly-Modules/natsio/model" - "github.com/Selly-Modules/natsio/subject" + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" ) // DistinctWithField ... diff --git a/go.sum b/go.sum index f3e58d6..85b108e 100644 --- a/go.sum +++ b/go.sum @@ -11,6 +11,7 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS 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 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= 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= @@ -24,10 +25,9 @@ github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47e 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 h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= 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= @@ -43,6 +43,7 @@ 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 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 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= @@ -52,10 +53,15 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd 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 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E= github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= +github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs= github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= 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= @@ -68,6 +74,7 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0 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 h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= 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= @@ -80,10 +87,12 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn 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 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= 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= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= From 1c10210bb96d4e1b2c4688ef55c5e74c8bcd0fe9 Mon Sep 17 00:00:00 2001 From: Tue Date: Tue, 11 Oct 2022 14:13:15 +0700 Subject: [PATCH 3/4] rebuild --- client/bank.go | 55 ++++++++++++++++++++++++++++++++++++ client/bank_branch.go | 39 +++++++++++++++++++++++++ model/bank_branch_reponse.go | 11 ++++++++ model/bank_branch_request.go | 6 ++++ model/bank_response.go | 21 ++++++++++++++ subject/bank.go | 17 +++++++++++ 6 files changed, 149 insertions(+) create mode 100644 client/bank.go create mode 100644 client/bank_branch.go create mode 100644 model/bank_branch_reponse.go create mode 100644 model/bank_branch_request.go create mode 100644 model/bank_response.go create mode 100644 subject/bank.go diff --git a/client/bank.go b/client/bank.go new file mode 100644 index 0000000..3391911 --- /dev/null +++ b/client/bank.go @@ -0,0 +1,55 @@ +package client + +import ( + "encoding/json" + "errors" + + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" +) + +// Bank ... +type Bank struct{} + +// GetBank ... +func GetBank() Bank { + return Bank{} +} + +func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) { + msg, err := natsio.GetServer().Request(subject.Bank.GetBankById, toBytes(bankID)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.BankBrief `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 Bank) CheckBankAndBranchByID(p model.BankBranchRequest) bool { + msg, err := natsio.GetServer().Request(subject.Bank.CheckBankAndBranchByID, toBytes(p)) + if err != nil { + return false + } + + var r struct { + Error string `json:"error"` + } + + if err = json.Unmarshal(msg.Data, &r); err != nil { + return false + } + return r.Error == "" +} diff --git a/client/bank_branch.go b/client/bank_branch.go new file mode 100644 index 0000000..5890e75 --- /dev/null +++ b/client/bank_branch.go @@ -0,0 +1,39 @@ +package client + +import ( + "encoding/json" + "errors" + + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" +) + +// BankBranch ... +type BankBranch struct{} + +// GetBankBranch ... +func GetBankBranch() BankBranch { + return BankBranch{} +} + +func (s BankBranch) GetBankBranchById(bankBranchID string) (*model.BankBranchBrief, error) { + msg, err := natsio.GetServer().Request(subject.Bank.GetBankBranchById, toBytes(bankBranchID)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.BankBranchBrief `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/bank_branch_reponse.go b/model/bank_branch_reponse.go new file mode 100644 index 0000000..1fa1432 --- /dev/null +++ b/model/bank_branch_reponse.go @@ -0,0 +1,11 @@ +package model + +// BankBranchBrief ... +type BankBranchBrief struct { + ID string `json:"_id"` + City string `json:"city"` + BankCode string `json:"bankCode"` + Bank string `json:"bank"` + Active bool `json:"active"` + Name string `json:"name"` +} diff --git a/model/bank_branch_request.go b/model/bank_branch_request.go new file mode 100644 index 0000000..6de1216 --- /dev/null +++ b/model/bank_branch_request.go @@ -0,0 +1,6 @@ +package model + +type BankBranchRequest struct { + BankID string `json:"bankId"` + BranchID string `json:"branchId"` +} diff --git a/model/bank_response.go b/model/bank_response.go new file mode 100644 index 0000000..74fc10e --- /dev/null +++ b/model/bank_response.go @@ -0,0 +1,21 @@ +package model + +// MultiLang ... +type MultiLang struct { + En string `json:"en"` + Vi string `json:"vi"` +} + +// BankBrief ... +type BankBrief struct { + ID string `json:"_id"` + Name MultiLang `json:"name"` + ShortName string `json:"shortName"` + Active bool `json:"active"` + BenBankName string `json:"benBankName"` + BankCode int `json:"bankCode"` + IsBranchRequired bool `json:"isBranchRequired"` + SearchString string `json:"searchString"` + BeneficiaryForVietinbank string `json:"beneficiaryForVietinbank"` + CreatedBy string `json:"createdBy,omitempty"` +} diff --git a/subject/bank.go b/subject/bank.go new file mode 100644 index 0000000..9f7f8bb --- /dev/null +++ b/subject/bank.go @@ -0,0 +1,17 @@ +package subject + +import "fmt" + +func getBankValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Bank, val) +} + +var Bank = struct { + GetBankById string + GetBankBranchById string + CheckBankAndBranchByID string +}{ + GetBankById: getBankValue("get_bank_by_id"), + GetBankBranchById: getBankValue("get_bank_branch_by_id"), + CheckBankAndBranchByID: getBankValue("check_bank_and_brach_by_id"), +} From cb7f37dea9a235edf09374a455e427493962b628 Mon Sep 17 00:00:00 2001 From: Tue Date: Tue, 11 Oct 2022 14:17:07 +0700 Subject: [PATCH 4/4] rebuild --- subject/config.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subject/config.go b/subject/config.go index 7a69414..4a2f9f3 100644 --- a/subject/config.go +++ b/subject/config.go @@ -6,6 +6,7 @@ var prefixes = struct { News string Warehouse string Location string + Bank string Supplier string Seller string }{ @@ -15,5 +16,6 @@ var prefixes = struct { Warehouse: "warehouse", Location: "location", Supplier: "supplier", + Bank: "bank", Seller: "seller", }