Merge pull request 'add nats staff' (#71) from feature/add-source-response-update-quantity into feature/campaign
Reviewed-on: #71
This commit is contained in:
commit
5a2a7fbbe0
|
@ -0,0 +1,41 @@
|
|||
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"
|
||||
)
|
||||
|
||||
// Staff ...
|
||||
type Staff struct{}
|
||||
|
||||
func GetStaff() Staff {
|
||||
return Staff{}
|
||||
}
|
||||
|
||||
// GetListStaffInfoByIds ...
|
||||
func (s Staff) GetListStaffInfoByIds(p model.GetListStaffRequest) (*model.ResponseListStaffInfo, error) {
|
||||
msg, err := natsio.GetServer().Request(subject.Staff.GetListStaffInfo, toBytes(p))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r struct {
|
||||
Data *model.ResponseListStaffInfo `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
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package model
|
||||
|
||||
// GetListStaffRequest ...
|
||||
type GetListStaffRequest struct {
|
||||
StaffIds []string `json:"staffIds"`
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package model
|
||||
|
||||
// ResponseListStaffInfo ...
|
||||
type ResponseListStaffInfo struct {
|
||||
Staffs []ResponseStaffInfo `json:"staffs"`
|
||||
}
|
||||
|
||||
// ResponseStaffInfo ...
|
||||
type ResponseStaffInfo struct {
|
||||
ID string `json:"_id"`
|
||||
Name string `json:"name"`
|
||||
}
|
|
@ -12,6 +12,7 @@ var prefixes = struct {
|
|||
SupplierUser string
|
||||
SupplierRole string
|
||||
SocialPost string
|
||||
Staff string
|
||||
}{
|
||||
Communication: "communication",
|
||||
Order: "order",
|
||||
|
@ -24,4 +25,5 @@ var prefixes = struct {
|
|||
SupplierUser: "supplier_user",
|
||||
SupplierRole: "supplier_role",
|
||||
SocialPost: "social_post",
|
||||
Staff: "staff",
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package subject
|
||||
|
||||
import "fmt"
|
||||
|
||||
func getStaffValue(val string) string {
|
||||
return fmt.Sprintf("%s.%s", prefixes.Staff, val)
|
||||
}
|
||||
|
||||
// Staff ...
|
||||
var Staff = struct {
|
||||
GetListStaffInfo string
|
||||
}{
|
||||
GetListStaffInfo: getStaffValue("get_list_staff_info"),
|
||||
}
|
Loading…
Reference in New Issue