feature/campaign #76

Merged
minhnguyen merged 12 commits from feature/campaign into master 2022-11-22 08:39:57 +00:00
5 changed files with 75 additions and 0 deletions
Showing only changes of commit 5a2a7fbbe0 - Show all commits

41
client/staff.go Normal file
View File

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

6
model/staff_request.go Normal file
View File

@ -0,0 +1,6 @@
package model
// GetListStaffRequest ...
type GetListStaffRequest struct {
StaffIds []string `json:"staffIds"`
}

12
model/staff_response.go Normal file
View File

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

View File

@ -12,6 +12,7 @@ var prefixes = struct {
SupplierUser string SupplierUser string
SupplierRole string SupplierRole string
SocialPost string SocialPost string
Staff string
}{ }{
Communication: "communication", Communication: "communication",
Order: "order", Order: "order",
@ -24,4 +25,5 @@ var prefixes = struct {
SupplierUser: "supplier_user", SupplierUser: "supplier_user",
SupplierRole: "supplier_role", SupplierRole: "supplier_role",
SocialPost: "social_post", SocialPost: "social_post",
Staff: "staff",
} }

14
subject/staff.go Normal file
View File

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