build authsms

This commit is contained in:
Tue 2022-11-08 13:53:52 +07:00
parent d946b993ee
commit ffff325e78
12 changed files with 275 additions and 148 deletions

View File

@ -17,14 +17,15 @@ func GetBank() Bank {
return Bank{}
}
func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) {
msg, err := natsio.GetServer().Request(subject.Bank.GetBankById, toBytes(bankID))
// GetBankInfo ...
func (s Bank) GetBankInfo(p []model.GetBankInfoRequest) ([]*model.ResponseBankInfo, error) {
msg, err := natsio.GetServer().Request(subject.Bank.GetBankInfo, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.BankBrief `json:"data"`
Data []*model.ResponseBankInfo `json:"data"`
Error string `json:"error"`
}
@ -38,7 +39,7 @@ func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) {
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))
if err != nil {
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 (
"encoding/json"
"errors"
"go.mongodb.org/mongo-driver/bson"
"git.selly.red/Selly-Modules/natsio"
"git.selly.red/Selly-Modules/natsio/model"
@ -101,9 +102,9 @@ func (s Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*mod
return r.Data, nil
}
// CreateWarehouseIntoServiceSupplier ...
func (s Supplier) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWarehousePayload) error {
msg, err := natsio.GetServer().Request(subject.Warehouse.CreateWarehouseIntoServiceSupplier, toBytes(p))
// SyncWarehouseIntoServiceSupplier ...
func (s Supplier) SyncWarehouseIntoServiceSupplier(p model.SyncSupplierWarehousePayload) error {
msg, err := natsio.GetServer().Request(subject.Warehouse.SyncWarehouseIntoServiceSupplier, toBytes(p))
if err != nil {
return err
}
@ -119,9 +120,104 @@ func (s Supplier) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWareh
return nil
}
// UpdateWarehouseIntoServiceSupplier ...
func (s Supplier) UpdateWarehouseIntoServiceSupplier(p model.UpdateSupplierWarehousePayload) error {
msg, err := natsio.GetServer().Request(subject.Warehouse.UpdateWarehouseIntoServiceSupplier, toBytes(p))
// GetListWarehouseFreeShip ...
func (s Supplier) GetListWarehouseFreeShip() (*model.SupplierListWarehouseFreeShipResponse, error) {
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 {
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
import "time"
// MultiLang ...
type MultiLang struct {
En string `json:"en"`
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 ...
type BankBrief struct {
ID string `json:"_id"`
@ -15,7 +27,14 @@ type BankBrief struct {
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"`
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
}
type CreateSupplierWarehousePayload struct {
type SyncSupplierWarehousePayload struct {
Supplier string `json:"supplier"`
Warehouse string `json:"warehouse"`
ProvinceCode int `json:"provinceCode"`
@ -31,10 +31,28 @@ type CreateSupplierWarehousePayload struct {
WardCode int `json:"wardCode"`
}
type UpdateSupplierWarehousePayload struct {
// SupplierCashflowCreatePayload ...
type SupplierCashflowCreatePayload struct {
Supplier string `json:"supplier"`
Warehouse string `json:"warehouse"`
ProvinceCode int `json:"provinceCode"`
DistrictCode int `json:"districtCode"`
WardCode int `json:"wardCode"`
Action string `json:"action"`
Name string `json:"name"`
TargetID string `json:"targetId"`
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"`
}
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 {
ID string `json:"_id"`
Name string `json:"name"`
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 {
GetBankById string
GetBankBranchById string
GetBankInfo string
CheckBankAndBranchByID string
}{
GetBankById: getBankValue("get_bank_by_id"),
GetBankBranchById: getBankValue("get_bank_branch_by_id"),
CheckBankAndBranchByID: getBankValue("check_bank_and_brach_by_id"),
GetBankInfo: getBankValue("get_bank_info"),
CheckBankAndBranchByID: getBankValue("check_bank_and_branch_by_id"),
}

View File

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

View File

@ -10,8 +10,20 @@ var Supplier = struct {
GetListSupplierInfo string
GetSupplierContractBySupplierID string
FindAll string
GetListWarehouseFreeShip string
CreateCashflow string
DeleteCashflow string
UpdateBalance string
GetCurrentBalance string
GetFreeShipInfo string
}{
GetListSupplierInfo: getSupplierValue("get_list_supplier_info"),
GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"),
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 {
CreateWarehouseIntoServiceSupplier string
UpdateWarehouseIntoServiceSupplier string
SyncWarehouseIntoServiceSupplier string
CreateOutboundRequest string
UpdateOutboundRequestLogistic string
CancelOutboundRequest string
@ -27,8 +26,7 @@ var Warehouse = struct {
GetWarehouses string
UpdateORDeliveryStatus string
}{
CreateWarehouseIntoServiceSupplier: getWarehouseValue("create_warehouse_into_service_supplier"),
UpdateWarehouseIntoServiceSupplier: getWarehouseValue("update_warehouse_into_service_supplier"),
SyncWarehouseIntoServiceSupplier: getWarehouseValue("sync_warehouse_into_service_supplier"),
AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"),
AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"),
CreateOutboundRequest: getWarehouseValue("create_outbound_request"),