natsio/client/staff.go

42 lines
799 B
Go
Raw Normal View History

2022-11-18 09:22:17 +00:00
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{}
}
2022-11-18 14:49:42 +00:00
// GetListStaffInfoByIds ...
func (s Staff) GetListStaffInfoByIds(p model.GetListStaffRequest) (*model.ResponseListStaffInfo, error) {
2022-11-18 10:47:26 +00:00
msg, err := natsio.GetServer().Request(subject.Staff.GetListStaffInfo, toBytes(p))
2022-11-18 09:22:17 +00:00
if err != nil {
return nil, err
}
var r struct {
2022-11-18 10:47:26 +00:00
Data *model.ResponseListStaffInfo `json:"data"`
Error string `json:"error"`
2022-11-18 09:22:17 +00:00
}
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
}