Merge branch 'develop' of git.selly.red:Selly-Modules/natsio into develop

This commit is contained in:
Sinh 2022-10-27 11:13:25 +07:00
commit ecb51cc5da
15 changed files with 118 additions and 138 deletions

View File

@ -1,60 +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"
"go.mongodb.org/mongo-driver/bson"
)
// AuthSMS ...
type AuthSMS struct{}
// GetAutSMS ...
func GetAutSMS() AuthSMS {
return AuthSMS{}
}
func (s AuthSMS) CreateUserSMSViaAuthSMS(p model.CreateUserSMSRequest) (*model.CreateUserSMSResponse, error) {
msg, err := natsio.GetServer().Request(subject.AuthSMS.CreateUserSMS, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.CreateUserSMSResponse `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 AuthSMS) GetListPermission() (*model.GetListPermissionResponse, error) {
msg, err := natsio.GetServer().Request(subject.AuthSMS.GetListPermission, toBytes(bson.M{}))
if err != nil {
return nil, err
}
var r struct {
Data *model.GetListPermissionResponse `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

@ -17,14 +17,14 @@ func GetBank() Bank {
return Bank{} return Bank{}
} }
func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) { func (s Bank) GetBankAndBranchByBankIDs(p model.GetBankAndBranchesRequest) ([]*model.ResponseBankAndBranches, error) {
msg, err := natsio.GetServer().Request(subject.Bank.GetBankById, toBytes(bankID)) msg, err := natsio.GetServer().Request(subject.Bank.GetBankAndBranchesByBankIDs, 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.ResponseBankAndBranches `json:"data"`
Error string `json:"error"` Error string `json:"error"`
} }
@ -38,7 +38,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

@ -119,7 +119,7 @@ func (s Supplier) UpdateWarehouseIntoServiceSupplier(p model.UpdateSupplierWareh
// GetWarehouseFreeship ... // GetWarehouseFreeship ...
func (s Supplier) GetWarehouseFreeship() (*model.ResponseListWarehouseIDByBusinessType, error) { func (s Supplier) GetWarehouseFreeship() (*model.ResponseListWarehouseIDByBusinessType, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.GetListWarehouseFreeship, toBytes(bson.M{})) msg, err := natsio.GetServer().Request(subject.Selly.GetListWarehouseFreeship, toBytes(bson.M{}))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -139,6 +139,25 @@ func (s Supplier) GetWarehouseFreeship() (*model.ResponseListWarehouseIDByBusine
return r.Data, nil return r.Data, nil
} }
// GetFreeshipsBySupplierIDs ...
func (s Supplier) GetFreeshipsBySupplierIDs(p model.GetFreeshipsBySupplierIds) (*model.ResponseListFreeshipsBySupplierIds, error) {
msg, err := natsio.GetServer().Request(subject.Selly.GetFreeshipsBySupplierIds, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseListFreeshipsBySupplierIds `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 ... // CreateCashflow ...
func (s Supplier) CreateCashflow(p model.SupplierCashflowCreatePayload) (*model.SupplierCashflowCreateResponse, error) { func (s Supplier) CreateCashflow(p model.SupplierCashflowCreatePayload) (*model.SupplierCashflowCreateResponse, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.CreateCashflow, toBytes(p)) msg, err := natsio.GetServer().Request(subject.Supplier.CreateCashflow, toBytes(p))

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"`
}

10
model/bank_request.go Normal file
View File

@ -0,0 +1,10 @@
package model
type CheckBankAndBranchByIDRequest struct {
BankID string `json:"bankId"`
BranchID string `json:"branchId"`
}
type GetBankAndBranchesRequest struct {
BankIDs []string `json:"bankIds"`
}

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 ResponseBankAndBranches struct {
Bank BankBrief `json:"bank"`
Branches []BranchBrief `json:"branches"`
} }

View File

@ -26,3 +26,19 @@ type ClickAction struct {
Type string `json:"type"` Type string `json:"type"`
Value string `json:"value"` Value string `json:"value"`
} }
// RequestCondition ...
type RequestCondition struct {
Code int `json:"code"`
Codes []int `json:"codes"`
DistrictCode int `json:"districtCode"`
ProvinceCode int `json:"provinceCode"`
Slug string `json:"slug"`
Slugs []string `json:"slugs"`
DistrictSlug string `json:"districtSlug"`
ProvinceSlug string `json:"provinceSlug"`
Keyword string `json:"keyword"`
Region string `json:"region"`
}

View File

@ -48,3 +48,7 @@ type SupplierCashflowCreatePayload struct {
Value float64 `json:"value"` Value float64 `json:"value"`
ClickAction *ClickAction `json:"clickAction"` ClickAction *ClickAction `json:"clickAction"`
} }
type GetFreeshipsBySupplierIds struct {
SupplierIDs []string `json:"supplierIds"`
}

View File

@ -37,3 +37,14 @@ type ResponseListWarehouseIDByBusinessType struct {
type SupplierCashflowCreateResponse struct { type SupplierCashflowCreateResponse struct {
ID string `json:"id"` ID string `json:"id"`
} }
type Freeship struct {
ID string `json:"_id"`
ShortName string `json:"shortName"`
MilestoneText []string `json:"milestoneText"`
}
type ResponseListFreeshipsBySupplierIds struct {
SupplierID string `json:"supplierId"`
Freeships []Freeship `json:"freeships"`
}

View File

@ -7,11 +7,9 @@ func getBankValue(val string) string {
} }
var Bank = struct { var Bank = struct {
GetBankById string GetBankAndBranchesByBankIDs string
GetBankBranchById string
CheckBankAndBranchByID string CheckBankAndBranchByID string
}{ }{
GetBankById: getBankValue("get_bank_by_id"), GetBankAndBranchesByBankIDs: getBankValue("get_bank_and_branches_by_bank_ids"),
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
}{ }{
Communication: "communication", Communication: "communication",
@ -19,5 +21,7 @@ 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",
} }

15
subject/selly.go Normal file
View File

@ -0,0 +1,15 @@
package subject
import "fmt"
func getSellyValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.Selly, val)
}
var Selly = struct {
GetFreeshipsBySupplierIds string
GetListWarehouseFreeship string
}{
GetFreeshipsBySupplierIds: getSellyValue("get_freeships_by_supplier_ids"),
GetListWarehouseFreeship: getSupplierValue("get_list_warehouse_freeship"),
}