build auth sms

This commit is contained in:
Tue 2022-10-25 15:27:05 +07:00
parent 25cb392d93
commit 9a2bd21534
6 changed files with 46 additions and 46 deletions

View File

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

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

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

View File

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

View File

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

View File

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