From 9297f2d9bd8cf81f695d898568a1b8a6fca68c5c Mon Sep 17 00:00:00 2001 From: Tue Date: Thu, 20 Oct 2022 14:32:32 +0700 Subject: [PATCH] update auth sms --- client/authsms.go | 38 ++++++++++++++++++++++++++++++++++++++ model/authsms_request.go | 8 ++++++++ model/authsms_response.go | 5 +++++ subject/authsms.go | 13 +++++++++++++ subject/config.go | 2 ++ 5 files changed, 66 insertions(+) create mode 100644 client/authsms.go create mode 100644 model/authsms_request.go create mode 100644 model/authsms_response.go create mode 100644 subject/authsms.go diff --git a/client/authsms.go b/client/authsms.go new file mode 100644 index 0000000..d98be55 --- /dev/null +++ b/client/authsms.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" +) + +// 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/model/authsms_request.go b/model/authsms_request.go new file mode 100644 index 0000000..c0b3078 --- /dev/null +++ b/model/authsms_request.go @@ -0,0 +1,8 @@ +package model + +type CreateUserSMSRequest struct { + Name string `json:"name"` + Phone string `json:"phone"` + Email string `json:"email"` + Supplier string `json:"supplier"` +} diff --git a/model/authsms_response.go b/model/authsms_response.go new file mode 100644 index 0000000..0effbbc --- /dev/null +++ b/model/authsms_response.go @@ -0,0 +1,5 @@ +package model + +type CreateUserSMSResponse struct { + ID string `json:"_id"` +} diff --git a/subject/authsms.go b/subject/authsms.go new file mode 100644 index 0000000..4b7a0ad --- /dev/null +++ b/subject/authsms.go @@ -0,0 +1,13 @@ +package subject + +import "fmt" + +func getAuthSMSValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.AuthSMS, val) +} + +var AuthSMS = struct { + CreateUserSMS string +}{ + CreateUserSMS: getAuthSMSValue("create_user_sms"), +} diff --git a/subject/config.go b/subject/config.go index 4a2f9f3..ccc480e 100644 --- a/subject/config.go +++ b/subject/config.go @@ -9,6 +9,7 @@ var prefixes = struct { Bank string Supplier string Seller string + AuthSMS string }{ Communication: "communication", Order: "order", @@ -18,4 +19,5 @@ var prefixes = struct { Supplier: "supplier", Bank: "bank", Seller: "seller", + AuthSMS: "auth_sms", }