diff --git a/client/supplier.go b/client/supplier.go index b091b78..559be4b 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -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 +} diff --git a/client/supplier_user.go b/client/supplier_user.go new file mode 100644 index 0000000..f5abc1f --- /dev/null +++ b/client/supplier_user.go @@ -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 +} diff --git a/model/common_request.go b/model/common_request.go index 0ce5163..c3cbac7 100644 --- a/model/common_request.go +++ b/model/common_request.go @@ -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"` +} diff --git a/model/supplier_request.go b/model/supplier_request.go index 5a19924..0a4b6fa 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -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"` +} diff --git a/model/supplier_response.go b/model/supplier_response.go index 3796e50..2a9ba1a 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -33,3 +33,7 @@ type SupplierAll struct { type ResponseListWarehouseIDByBusinessType struct { Warehouses []string `json:"warehouses"` } + +type SupplierCashflowCreateResponse struct { + ID string `json:"id"` +} diff --git a/model/authsms_request.go b/model/supplier_user_request.go similarity index 84% rename from model/authsms_request.go rename to model/supplier_user_request.go index df718bd..6dc9df8 100644 --- a/model/authsms_request.go +++ b/model/supplier_user_request.go @@ -1,6 +1,6 @@ package model -type CreateUserSMSRequest struct { +type CreateSupplierUserRequest struct { Name string `json:"name"` Phone string `json:"phone"` Email string `json:"email"` diff --git a/model/authsms_response.go b/model/supplier_user_response.go similarity index 75% rename from model/authsms_response.go rename to model/supplier_user_response.go index d1e6b24..a71ee2a 100644 --- a/model/authsms_response.go +++ b/model/supplier_user_response.go @@ -1,6 +1,6 @@ package model -type CreateUserSMSResponse struct { +type CreateSupplierUserResponse struct { ID string `json:"_id"` } diff --git a/subject/authsms.go b/subject/authsms.go index b89ca3c..5b6b2e4 100644 --- a/subject/authsms.go +++ b/subject/authsms.go @@ -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 { diff --git a/subject/config.go b/subject/config.go index ccc480e..d50d9d4 100644 --- a/subject/config.go +++ b/subject/config.go @@ -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", } diff --git a/subject/supplier.go b/subject/supplier.go index f249ef1..da95ef9 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -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"), }