refactor-location #134

Closed
trunglam wants to merge 270 commits from refactor-location into master
12 changed files with 275 additions and 148 deletions
Showing only changes of commit ffff325e78 - Show all commits

View File

@ -17,14 +17,15 @@ func GetBank() Bank {
return Bank{} return Bank{}
} }
func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) { // GetBankInfo ...
msg, err := natsio.GetServer().Request(subject.Bank.GetBankById, toBytes(bankID)) func (s Bank) GetBankInfo(p []model.GetBankInfoRequest) ([]*model.ResponseBankInfo, error) {
msg, err := natsio.GetServer().Request(subject.Bank.GetBankInfo, toBytes(p))
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r struct { var r struct {
Data *model.BankBrief `json:"data"` Data []*model.ResponseBankInfo `json:"data"`
Error string `json:"error"` Error string `json:"error"`
} }
@ -38,7 +39,7 @@ func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) {
return r.Data, nil return r.Data, nil
} }
func (s Bank) CheckBankAndBranchByID(p model.BankBranchRequest) bool { func (s Bank) CheckBankAndBranchByID(p model.CheckBankAndBranchByIDRequest) bool {
msg, err := natsio.GetServer().Request(subject.Bank.CheckBankAndBranchByID, toBytes(p)) msg, err := natsio.GetServer().Request(subject.Bank.CheckBankAndBranchByID, toBytes(p))
if err != nil { if err != nil {
return false return false

View File

@ -1,39 +0,0 @@
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
}

View File

@ -3,6 +3,7 @@ package client
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"go.mongodb.org/mongo-driver/bson"
"git.selly.red/Selly-Modules/natsio" "git.selly.red/Selly-Modules/natsio"
"git.selly.red/Selly-Modules/natsio/model" "git.selly.red/Selly-Modules/natsio/model"
@ -101,9 +102,9 @@ func (s Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*mod
return r.Data, nil return r.Data, nil
} }
// CreateWarehouseIntoServiceSupplier ... // SyncWarehouseIntoServiceSupplier ...
func (s Supplier) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWarehousePayload) error { func (s Supplier) SyncWarehouseIntoServiceSupplier(p model.SyncSupplierWarehousePayload) error {
msg, err := natsio.GetServer().Request(subject.Warehouse.CreateWarehouseIntoServiceSupplier, toBytes(p)) msg, err := natsio.GetServer().Request(subject.Warehouse.SyncWarehouseIntoServiceSupplier, toBytes(p))
if err != nil { if err != nil {
return err return err
} }
@ -119,9 +120,104 @@ func (s Supplier) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWareh
return nil return nil
} }
// UpdateWarehouseIntoServiceSupplier ... // GetListWarehouseFreeShip ...
func (s Supplier) UpdateWarehouseIntoServiceSupplier(p model.UpdateSupplierWarehousePayload) error { func (s Supplier) GetListWarehouseFreeShip() (*model.SupplierListWarehouseFreeShipResponse, error) {
msg, err := natsio.GetServer().Request(subject.Warehouse.UpdateWarehouseIntoServiceSupplier, toBytes(p)) msg, err := natsio.GetServer().Request(subject.Supplier.GetListWarehouseFreeShip, toBytes(bson.M{}))
if err != nil {
return nil, err
}
var r struct {
Data *model.SupplierListWarehouseFreeShipResponse `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
}
// GetFreeShipInfo ...
func (s Supplier) GetFreeShipInfo(p model.SupplierFreeShipInfoRequestPayload) ([]*model.SupplierFreeShipInfoResponse, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.GetFreeShipInfo, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data []*model.SupplierFreeShipInfoResponse `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
}
// CreateCashflow ...
func (s Supplier) CreateCashflow(p model.SupplierCashflowCreatePayload) (*model.SupplierCashflowCreateResponse, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.CreateCashflow, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Error string `json:"error"`
Data *model.SupplierCashflowCreateResponse `json:"data"`
}
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) UpdateBalance(p model.SupplierUpdateBalanceReq) (*model.SupplierUpdateBalanceRes, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.UpdateBalance, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Error string `json:"error"`
Data *model.SupplierUpdateBalanceRes `json:"data"`
}
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) GetCurrentBalance(p model.SupplierGetCurrentBalanceReq) (*model.SupplierGetCurrentBalanceRes, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.GetCurrentBalance, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Error string `json:"error"`
Data *model.SupplierGetCurrentBalanceRes `json:"data"`
}
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) DeleteCashflow(p model.SupplierDeleteCashflowReq) error {
msg, err := natsio.GetServer().Request(subject.Supplier.DeleteCashflow, toBytes(p))
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,11 +0,0 @@
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"`
}

View File

@ -1,6 +0,0 @@
package model
type BankBranchRequest struct {
BankID string `json:"bankId"`
BranchID string `json:"branchId"`
}

View File

@ -1,11 +1,23 @@
package model package model
import "time"
// MultiLang ... // MultiLang ...
type MultiLang struct { type MultiLang struct {
En string `json:"en"` En string `json:"en"`
Vi string `json:"vi"` Vi string `json:"vi"`
} }
// BankBranchBrief ...
type BranchBrief struct {
ID string `json:"_id"`
City string `json:"city"`
BankCode string `json:"bankCode"`
BankID string `json:"bankId"`
Active bool `json:"active"`
Name string `json:"name"`
}
// BankBrief ... // BankBrief ...
type BankBrief struct { type BankBrief struct {
ID string `json:"_id"` ID string `json:"_id"`
@ -15,7 +27,14 @@ type BankBrief struct {
BenBankName string `json:"benBankName"` BenBankName string `json:"benBankName"`
BankCode int `json:"bankCode"` BankCode int `json:"bankCode"`
IsBranchRequired bool `json:"isBranchRequired"` IsBranchRequired bool `json:"isBranchRequired"`
SearchString string `json:"searchString"`
BeneficiaryForVietinbank string `json:"beneficiaryForVietinbank"` BeneficiaryForVietinbank string `json:"beneficiaryForVietinbank"`
CreatedBy string `json:"createdBy,omitempty"` CreatedBy string `json:"createdBy,omitempty"`
CreatedAt time.Time `json:"createdAt"`
BranchTotal int64 `json:"branchTotal"`
Logo interface{} `json:"logo"`
}
type ResponseBankInfo struct {
Bank BankBrief `json:"bank"`
Branch BranchBrief `json:"branch"`
} }

View File

@ -23,7 +23,7 @@ type SupplierRequestPayload struct {
ContractStatus string ContractStatus string
} }
type CreateSupplierWarehousePayload struct { type SyncSupplierWarehousePayload struct {
Supplier string `json:"supplier"` Supplier string `json:"supplier"`
Warehouse string `json:"warehouse"` Warehouse string `json:"warehouse"`
ProvinceCode int `json:"provinceCode"` ProvinceCode int `json:"provinceCode"`
@ -31,10 +31,28 @@ type CreateSupplierWarehousePayload struct {
WardCode int `json:"wardCode"` WardCode int `json:"wardCode"`
} }
type UpdateSupplierWarehousePayload struct { // SupplierCashflowCreatePayload ...
type SupplierCashflowCreatePayload struct {
Supplier string `json:"supplier"` Supplier string `json:"supplier"`
Warehouse string `json:"warehouse"` Action string `json:"action"`
ProvinceCode int `json:"provinceCode"` Name string `json:"name"`
DistrictCode int `json:"districtCode"` TargetID string `json:"targetId"`
WardCode int `json:"wardCode"` Value float64 `json:"value"`
ClickAction *ClickAction `json:"clickAction"`
}
type SupplierFreeShipInfoRequestPayload struct {
SupplierIDs []string `json:"supplierIds"`
}
type SupplierUpdateBalanceReq struct {
SupplierID string `json:"supplierId"`
}
type SupplierGetCurrentBalanceReq struct {
SupplierID string `json:"supplierId"`
}
type SupplierDeleteCashflowReq struct {
CashflowID string `json:"cashflowId"`
} }

View File

@ -30,8 +30,45 @@ type SupplierAll struct {
Total int64 `json:"total"` Total int64 `json:"total"`
} }
type SupplierListWarehouseFreeShipResponse struct {
Warehouses []string `json:"warehouses"`
}
type SupplierCashflowCreateResponse struct {
ID string `json:"id"`
}
type FreeShip struct {
ID string `json:"_id"`
ShortName string `json:"shortName"`
ListMilestoneText []string `json:"milestoneText"`
Order int `json:"-"`
}
type SupplierFreeShipInfoResponse struct {
SupplierID string `json:"supplierId"`
FreeShips []FreeShip `json:"freeShips"`
}
type SupplierShort struct { type SupplierShort struct {
ID string `json:"_id"` ID string `json:"_id"`
Name string `json:"name"` Name string `json:"name"`
Logo interface{} `json:"logo"` Logo interface{} `json:"logo"`
} }
type SupplierUpdateBalanceRes struct {
CurrentCash float64 `json:"currentCash"`
TotalPendingCash float64 `json:"totalPendingCash"`
OrderPendingCash float64 `json:"orderPendingCash"`
OrderWaitingForReconcileCash float64 `json:"orderWaitingForReconcileCash"`
OrderReconciledCash float64 `json:"orderReconciledCash"`
WithdrawPendingCash float64 `json:"withdrawPendingCash"`
WithdrawSuccessCash float64 `json:"withdrawSuccessCash"`
WithdrawRejectCash float64 `json:"withdrawRejectCash"`
ChangeBalanceRequestApproved float64 `json:"changeBalanceRequestApproved"`
UpdatedAt string `json:"updatedAt"`
}
type SupplierGetCurrentBalanceRes struct {
CurrentCash float64 `json:"currentCash"`
}

View File

@ -7,11 +7,9 @@ func getBankValue(val string) string {
} }
var Bank = struct { var Bank = struct {
GetBankById string GetBankInfo string
GetBankBranchById string
CheckBankAndBranchByID string CheckBankAndBranchByID string
}{ }{
GetBankById: getBankValue("get_bank_by_id"), GetBankInfo: getBankValue("get_bank_info"),
GetBankBranchById: getBankValue("get_bank_branch_by_id"), CheckBankAndBranchByID: getBankValue("check_bank_and_branch_by_id"),
CheckBankAndBranchByID: getBankValue("check_bank_and_brach_by_id"),
} }

View File

@ -9,6 +9,8 @@ var prefixes = struct {
Bank string Bank string
Supplier string Supplier string
Seller string Seller string
AuthSMS string
Selly string
SupplierUser string SupplierUser string
SupplierRole string SupplierRole string
SupplierPermission string SupplierPermission string
@ -21,6 +23,8 @@ var prefixes = struct {
Supplier: "supplier", Supplier: "supplier",
Bank: "bank", Bank: "bank",
Seller: "seller", Seller: "seller",
AuthSMS: "auth_sms",
Selly: "selly",
SupplierUser: "supplier_user", SupplierUser: "supplier_user",
SupplierRole: "supplier_role", SupplierRole: "supplier_role",
SupplierPermission: "supplier_permission", SupplierPermission: "supplier_permission",

View File

@ -10,8 +10,20 @@ var Supplier = struct {
GetListSupplierInfo string GetListSupplierInfo string
GetSupplierContractBySupplierID string GetSupplierContractBySupplierID string
FindAll string FindAll string
GetListWarehouseFreeShip string
CreateCashflow string
DeleteCashflow string
UpdateBalance string
GetCurrentBalance string
GetFreeShipInfo string
}{ }{
GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetListSupplierInfo: getSupplierValue("get_list_supplier_info"),
GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"),
FindAll: getSupplierValue("find_all"), FindAll: getSupplierValue("find_all"),
GetListWarehouseFreeShip: getSupplierValue("get_list_warehouse_free_ship"),
CreateCashflow: getSupplierValue("create_cashflow"),
DeleteCashflow: getSupplierValue("delete_cashflow"),
UpdateBalance: getSupplierValue("update_balance"),
GetCurrentBalance: getSupplierValue("get_current_balance"),
GetFreeShipInfo: getSupplierValue("get_free_ship_info"),
} }

View File

@ -7,8 +7,7 @@ func getWarehouseValue(val string) string {
} }
var Warehouse = struct { var Warehouse = struct {
CreateWarehouseIntoServiceSupplier string SyncWarehouseIntoServiceSupplier string
UpdateWarehouseIntoServiceSupplier string
CreateOutboundRequest string CreateOutboundRequest string
UpdateOutboundRequestLogistic string UpdateOutboundRequestLogistic string
CancelOutboundRequest string CancelOutboundRequest string
@ -27,8 +26,7 @@ var Warehouse = struct {
GetWarehouses string GetWarehouses string
UpdateORDeliveryStatus string UpdateORDeliveryStatus string
}{ }{
CreateWarehouseIntoServiceSupplier: getWarehouseValue("create_warehouse_into_service_supplier"), SyncWarehouseIntoServiceSupplier: getWarehouseValue("sync_warehouse_into_service_supplier"),
UpdateWarehouseIntoServiceSupplier: getWarehouseValue("update_warehouse_into_service_supplier"),
AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"), AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"),
AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"), AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"),
CreateOutboundRequest: getWarehouseValue("create_outbound_request"), CreateOutboundRequest: getWarehouseValue("create_outbound_request"),