Merge pull request 'build-auth-sms' (#49) from build-auth-sms into master

Reviewed-on: #49
This commit is contained in:
tuenguyen 2022-10-25 08:27:23 +00:00
commit fd7c0ad0fd
5 changed files with 68 additions and 0 deletions

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

@ -0,0 +1,10 @@
package model
type CreateSupplierUserRequest struct {
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
Supplier string `json:"supplier"`
Role string `json:"role"`
Password string `json:"password"`
}

View File

@ -0,0 +1,5 @@
package model
type CreateSupplierUserResponse 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.SupplierUser, val)
}
var SupplierUser = struct {
CreateSupplierUser string
}{
CreateSupplierUser: getAuthSMSValue("create_supplier_user"),
}

View File

@ -9,6 +9,7 @@ var prefixes = struct {
Bank string Bank string
Supplier string Supplier string
Seller string Seller string
SupplierUser 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",
SupplierUser: "supplier_user",
} }