update auth sms

This commit is contained in:
Tue 2022-10-20 14:32:32 +07:00
parent c2887223c7
commit 9297f2d9bd
5 changed files with 66 additions and 0 deletions

38
client/authsms.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"
)
// 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
}

8
model/authsms_request.go Normal file
View File

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

View File

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

13
subject/authsms.go Normal file
View File

@ -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"),
}

View File

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