From ee32f2d8bb6aa8c0b8e2e6002a1e7c1c10c98e9e Mon Sep 17 00:00:00 2001 From: Tue Date: Wed, 14 Sep 2022 17:23:01 +0700 Subject: [PATCH] bank info --- client/bank.go | 2 +- client/bank_branch.go | 39 ++++++++++++++++++++++++++ client/warehouse.go | 18 ++++++++++++ model/bank_branch_reponse.go | 11 ++++++++ model/bank_request.go | 6 ---- model/bank_response.go | 2 -- model/warehouse_response.go | 8 ++++++ subject/bank.go | 5 ++-- subject/warehouse.go | 54 +++++++++++++++++++----------------- 9 files changed, 108 insertions(+), 37 deletions(-) create mode 100644 client/bank_branch.go create mode 100644 model/bank_branch_reponse.go delete mode 100644 model/bank_request.go diff --git a/client/bank.go b/client/bank.go index 0a5b7a3..5650b2f 100644 --- a/client/bank.go +++ b/client/bank.go @@ -17,7 +17,7 @@ func GetBank() Bank { return Bank{} } -func (s Bank) GetBankById(bankID model.BankRequestPayload) (*model.BankBrief, error) { +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 diff --git a/client/bank_branch.go b/client/bank_branch.go new file mode 100644 index 0000000..75ccb9f --- /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() Bank { + return Bank{} +} + +func (s Bank) 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/warehouse.go b/client/warehouse.go index 6c04925..0b85b6d 100644 --- a/client/warehouse.go +++ b/client/warehouse.go @@ -126,3 +126,21 @@ func (w Warehouse) GetConfigByWarehouseID(warehouseID string) (*model.WarehouseC } return r.Data, nil } + +// CreateWarehouseIntoServiceSupplier ... +func (w Warehouse) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWarehouseResponse) 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 +} 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_request.go b/model/bank_request.go deleted file mode 100644 index 2093aca..0000000 --- a/model/bank_request.go +++ /dev/null @@ -1,6 +0,0 @@ -package model - -// BankRequestPayload ... -type BankRequestPayload struct { - ID string `json:"_id"` -} diff --git a/model/bank_response.go b/model/bank_response.go index c27d7fd..74fc10e 100644 --- a/model/bank_response.go +++ b/model/bank_response.go @@ -12,8 +12,6 @@ type BankBrief struct { Name MultiLang `json:"name"` ShortName string `json:"shortName"` Active bool `json:"active"` - CreatedAt string `json:"createdAt"` - UpdatedAt string `json:"updatedAt"` BenBankName string `json:"benBankName"` BankCode int `json:"bankCode"` IsBranchRequired bool `json:"isBranchRequired"` diff --git a/model/warehouse_response.go b/model/warehouse_response.go index 2429743..e516950 100644 --- a/model/warehouse_response.go +++ b/model/warehouse_response.go @@ -120,3 +120,11 @@ type WarehouseNatsResponse struct { CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } + +type CreateSupplierWarehouseResponse 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 index 71bbdbe..f6e8d67 100644 --- a/subject/bank.go +++ b/subject/bank.go @@ -7,7 +7,8 @@ func getBankValue(val string) string { } var Bank = struct { - GetBankById string + GetBankById string + GetBankBranchById string }{ - GetBankById: getBankValue("get_bank_by_id"), + GetBankBranchById: getBankValue("get_bank_by_id"), } diff --git a/subject/warehouse.go b/subject/warehouse.go index 5d0a81c..2824c33 100644 --- a/subject/warehouse.go +++ b/subject/warehouse.go @@ -7,31 +7,33 @@ func getWarehouseValue(val string) string { } var Warehouse = struct { - CreateOutboundRequest string - UpdateOutboundRequestLogistic string - CancelOutboundRequest string - GetConfiguration string - SyncORStatus string - WebhookTNC string - WebhookGlobalCare string - FindOne string - FindByCondition string - Distinct string - Count string - AfterUpdateWarehouse string - AfterCreateWarehouse string + CreateOutboundRequest string + UpdateOutboundRequestLogistic string + CancelOutboundRequest string + GetConfiguration string + SyncORStatus string + WebhookTNC string + WebhookGlobalCare string + FindOne string + FindByCondition string + Distinct string + Count string + AfterUpdateWarehouse string + AfterCreateWarehouse string + CreateWarehouseIntoServiceSupplier 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"), - GetConfiguration: getWarehouseValue("get_configuration"), - SyncORStatus: getWarehouseValue("sync_or_status"), - WebhookTNC: getWarehouseValue("webhook_tnc"), - WebhookGlobalCare: getWarehouseValue("webhook_global_care"), - FindOne: getWarehouseValue("find_one"), - FindByCondition: getWarehouseValue("find_all_by_condition"), - Distinct: getWarehouseValue("distinct"), - Count: getWarehouseValue("count"), + AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"), + AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"), + CreateOutboundRequest: getWarehouseValue("create_outbound_request"), + UpdateOutboundRequestLogistic: getWarehouseValue("update_outbound_request_logistic_info"), + CancelOutboundRequest: getWarehouseValue("cancel_outbound_request"), + GetConfiguration: getWarehouseValue("get_configuration"), + SyncORStatus: getWarehouseValue("sync_or_status"), + WebhookTNC: getWarehouseValue("webhook_tnc"), + WebhookGlobalCare: getWarehouseValue("webhook_global_care"), + FindOne: getWarehouseValue("find_one"), + FindByCondition: getWarehouseValue("find_all_by_condition"), + Distinct: getWarehouseValue("distinct"), + Count: getWarehouseValue("count"), + CreateWarehouseIntoServiceSupplier: getWarehouseValue("create_warehouse_into_service_supplier"), }