diff --git a/client/bank.go b/client/bank.go new file mode 100644 index 0000000..86b3d94 --- /dev/null +++ b/client/bank.go @@ -0,0 +1,55 @@ +package client + +import ( + "encoding/json" + "errors" + + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/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..0ca9460 --- /dev/null +++ b/client/bank_branch.go @@ -0,0 +1,39 @@ +package client + +import ( + "encoding/json" + "errors" + + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/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/client/seller.go b/client/seller.go new file mode 100644 index 0000000..ec3ab83 --- /dev/null +++ b/client/seller.go @@ -0,0 +1,40 @@ +package client + +import ( + "encoding/json" + "errors" + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" +) + +// Seller ... +type Seller struct{} + +// GetSeller ... +func GetSeller() Seller { + return Seller{} +} + +// GetSellerInfoByID ... +func (s Seller) GetSellerInfoByID(p model.GetSellerByIDRequest) (*model.ResponseSellerInfo, error) { + msg, err := natsio.GetServer().Request(subject.Seller.GetSellerInfoByID, toBytes(p)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseSellerInfo `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 index 700d714..41a1849 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -79,3 +79,39 @@ func (s Supplier) FindAll(supplierID model.SupplierRequestPayload) (*model.Suppl return r.Data, nil } + +// CreateWarehouseIntoServiceSupplier ... +func (s Supplier) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWarehousePayload) error { + msg, err := natsio.GetServer().Request(subject.Warehouse.CreateWarehouseIntoServiceSupplier, 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 +} + +// UpdateWarehouseIntoServiceSupplier ... +func (s Supplier) UpdateWarehouseIntoServiceSupplier(p model.UpdateSupplierWarehousePayload) error { + msg, err := natsio.GetServer().Request(subject.Warehouse.UpdateWarehouseIntoServiceSupplier, 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 +} 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/model/seller_request.go b/model/seller_request.go new file mode 100644 index 0000000..997cd97 --- /dev/null +++ b/model/seller_request.go @@ -0,0 +1,8 @@ +package model + +import "go.mongodb.org/mongo-driver/bson/primitive" + +// GetSellerByIDRequest ... +type GetSellerByIDRequest struct { + SellerID primitive.ObjectID `json:"sellerId"` +} diff --git a/model/seller_response.go b/model/seller_response.go new file mode 100644 index 0000000..6b7d698 --- /dev/null +++ b/model/seller_response.go @@ -0,0 +1,8 @@ +package model + +// ResponseSellerInfo ... +type ResponseSellerInfo struct { + ID string `json:"id"` + Name string `json:"name"` + Code string `json:"code"` +} diff --git a/model/supplier_request.go b/model/supplier_request.go index 04d15d5..5a19924 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -22,3 +22,19 @@ type SupplierRequestPayload struct { PIC string ContractStatus string } + +type CreateSupplierWarehousePayload struct { + Supplier string `json:"supplier"` + Warehouse string `json:"warehouse"` + ProvinceCode int `json:"provinceCode"` + DistrictCode int `json:"districtCode"` + WardCode int `json:"wardCode"` +} + +type UpdateSupplierWarehousePayload struct { + Supplier string `json:"supplier"` + Warehouse string `json:"warehouse"` + ProvinceCode int `json:"provinceCode"` + DistrictCode int `json:"districtCode"` + WardCode int `json:"wardCode"` +} 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"), +} diff --git a/subject/config.go b/subject/config.go index dfeea56..5483c71 100644 --- a/subject/config.go +++ b/subject/config.go @@ -5,11 +5,15 @@ var prefixes = struct { Order string Warehouse string Location string + Bank string Supplier string + Seller string }{ Communication: "communication", Order: "order", Warehouse: "warehouse", Location: "location", Supplier: "supplier", + Bank: "bank", + Seller: "seller", } diff --git a/subject/seller.go b/subject/seller.go new file mode 100644 index 0000000..033f993 --- /dev/null +++ b/subject/seller.go @@ -0,0 +1,14 @@ +package subject + +import "fmt" + +func getSellerValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Seller, val) +} + +// Seller ... +var Seller = struct { + GetSellerInfoByID string +}{ + GetSellerInfoByID: getSellerValue("get_seller_info_by_id"), +} diff --git a/subject/warehouse.go b/subject/warehouse.go index a0480ae..ed29f21 100644 --- a/subject/warehouse.go +++ b/subject/warehouse.go @@ -21,6 +21,8 @@ var Warehouse = struct { AfterUpdateWarehouse string AfterCreateWarehouse string UpdateIsClosedSupplier string + CreateWarehouseIntoServiceSupplier string + UpdateWarehouseIntoServiceSupplier string }{ AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"), AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"), @@ -36,4 +38,6 @@ var Warehouse = struct { Distinct: getWarehouseValue("distinct"), Count: getWarehouseValue("count"), UpdateIsClosedSupplier: getWarehouseValue("update_is_closed_supplier"), + CreateWarehouseIntoServiceSupplier: getWarehouseValue("create_warehouse_into_service_supplier"), + UpdateWarehouseIntoServiceSupplier: getWarehouseValue("update_warehouse_into_service_supplier"), }