From 9a2bd21534926fd23efc35ff8847543273d98f56 Mon Sep 17 00:00:00 2001 From: Tue Date: Tue, 25 Oct 2022 15:27:05 +0700 Subject: [PATCH 1/2] build auth sms --- client/authsms.go | 38 ------------------- client/supplier_user.go | 38 +++++++++++++++++++ ...ms_request.go => supplier_user_request.go} | 2 +- ..._response.go => supplier_user_response.go} | 2 +- subject/authsms.go | 8 ++-- subject/config.go | 4 +- 6 files changed, 46 insertions(+), 46 deletions(-) delete mode 100644 client/authsms.go create mode 100644 client/supplier_user.go rename model/{authsms_request.go => supplier_user_request.go} (84%) rename model/{authsms_response.go => supplier_user_response.go} (50%) diff --git a/client/authsms.go b/client/authsms.go deleted file mode 100644 index d98be55..0000000 --- a/client/authsms.go +++ /dev/null @@ -1,38 +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" -) - -// 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 -} 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/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 50% rename from model/authsms_response.go rename to model/supplier_user_response.go index 0effbbc..9583b76 100644 --- a/model/authsms_response.go +++ b/model/supplier_user_response.go @@ -1,5 +1,5 @@ package model -type CreateUserSMSResponse struct { +type CreateSupplierUserResponse struct { ID string `json:"_id"` } diff --git a/subject/authsms.go b/subject/authsms.go index 4b7a0ad..fd63148 100644 --- a/subject/authsms.go +++ b/subject/authsms.go @@ -3,11 +3,11 @@ 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 { - CreateUserSMS string +var SupplierUser = struct { + CreateSupplierUser string }{ - CreateUserSMS: getAuthSMSValue("create_user_sms"), + CreateSupplierUser: getAuthSMSValue("create_supplier_user"), } 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", } From 20f460b4ef27d6d44b74e1a099904ab4112472b5 Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 26 Oct 2022 17:56:15 +0700 Subject: [PATCH 2/2] create supplier cashflow --- client/supplier.go | 19 +++++++++++++++++++ model/common_request.go | 6 ++++++ model/supplier_request.go | 10 ++++++++++ model/supplier_response.go | 4 ++++ subject/supplier.go | 2 ++ 5 files changed, 41 insertions(+) diff --git a/client/supplier.go b/client/supplier.go index 1ed20d0..f742f94 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -136,3 +136,22 @@ func (s Supplier) UpdateWarehouseIntoServiceSupplier(p model.UpdateSupplierWareh } return 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/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 975a8de..8efdb2c 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -29,3 +29,7 @@ type SupplierAll struct { Suppliers []SupplierBrief `json:"suppliers"` Total int64 `json:"total"` } + +type SupplierCashflowCreateResponse struct { + ID string `json:"id"` +} diff --git a/subject/supplier.go b/subject/supplier.go index 17ca8d0..1b86c12 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -10,8 +10,10 @@ var Supplier = struct { GetListSupplierInfo string GetSupplierContractBySupplierID string FindAll string + CreateCashflow string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), FindAll: getSupplierValue("find_all"), + CreateCashflow: getSupplierValue("create_cashflow"), }