Merge branch 'refactor-supplier' into develop

This commit is contained in:
Sinh 2022-10-26 17:58:34 +07:00
commit 855cf4ad5f
10 changed files with 84 additions and 5 deletions

View File

@ -138,3 +138,22 @@ func (s Supplier) GetWarehouseFreeship() (*model.ResponseListWarehouseIDByBusine
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
}

38
client/supplier_user.go Normal file
View File

@ -0,0 +1,38 @@
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"
)
// SupplierUser ...
type SupplierUser struct{}
// GetSupplierUser ...
func GetSupplierUser() SupplierUser {
return SupplierUser{}
}
func (s SupplierUser) CreateSupplierUserS(p model.CreateSupplierUserRequest) (*model.CreateSupplierUserResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateSupplierUser, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.CreateSupplierUserResponse `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

@ -20,3 +20,9 @@ type ActionBy struct {
ID string `json:"id"`
Name string `json:"name"`
}
// ClickAction ...
type ClickAction struct {
Type string `json:"type"`
Value string `json:"value"`
}

View File

@ -38,3 +38,13 @@ type UpdateSupplierWarehousePayload struct {
DistrictCode int `json:"districtCode"`
WardCode int `json:"wardCode"`
}
// SupplierCashflowCreatePayload ...
type SupplierCashflowCreatePayload struct {
Supplier string `json:"supplier"`
Action string `json:"action"`
Name string `json:"name"`
TargetID string `json:"targetId"`
Value float64 `json:"value"`
ClickAction *ClickAction `json:"clickAction"`
}

View File

@ -33,3 +33,7 @@ type SupplierAll struct {
type ResponseListWarehouseIDByBusinessType struct {
Warehouses []string `json:"warehouses"`
}
type SupplierCashflowCreateResponse struct {
ID string `json:"id"`
}

View File

@ -1,6 +1,6 @@
package model
type CreateUserSMSRequest struct {
type CreateSupplierUserRequest struct {
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`

View File

@ -1,6 +1,6 @@
package model
type CreateUserSMSResponse struct {
type CreateSupplierUserResponse struct {
ID string `json:"_id"`
}

View File

@ -3,7 +3,7 @@ package subject
import "fmt"
func getAuthSMSValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.AuthSMS, val)
return fmt.Sprintf("%s.%s", prefixes.SupplierUser, val)
}
var AuthSMS = struct {

View File

@ -9,7 +9,7 @@ var prefixes = struct {
Bank string
Supplier string
Seller string
AuthSMS string
SupplierUser string
}{
Communication: "communication",
Order: "order",
@ -19,5 +19,5 @@ var prefixes = struct {
Supplier: "supplier",
Bank: "bank",
Seller: "seller",
AuthSMS: "auth_sms",
SupplierUser: "supplier_user",
}

View File

@ -11,9 +11,11 @@ var Supplier = struct {
GetSupplierContractBySupplierID string
FindAll string
GetListWarehouseFreeship string
CreateCashflow string
}{
GetListSupplierInfo: getSupplierValue("get_list_supplier_info"),
GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"),
FindAll: getSupplierValue("find_all"),
GetListWarehouseFreeship: getSupplierValue("get_list_warehouse_freeship"),
CreateCashflow: getSupplierValue("create_cashflow"),
}