get staff by notification action #64

Merged
Ghost merged 1 commits from feaure/staff-getinfo into develop 2022-11-18 09:23:36 +00:00
5 changed files with 78 additions and 0 deletions

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{}
}
// GetListStaffInfoByNotificationAction ...
func (s Staff) GetListStaffInfoByNotificationAction(p model.GetListStaffByNotificationActionRequest) (*model.ResponseListStaffInfoByNotificationAction, error) {
msg, err := natsio.GetServer().Request(subject.Staff.GetListStaffInfoByNotificationAction, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseListStaffInfoByNotificationAction `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
}

8
model/staff_request.go Normal file
View File

@ -0,0 +1,8 @@
package model
// GetListStaffByNotificationActionRequest ...
type GetListStaffByNotificationActionRequest struct {
CreatedBys []string `json:"createdBys"`
ApprovedBys []string `json:"approvedBys"`
CancelledBys []string `json:"cancelledBys"`
}

14
model/staff_response.go Normal file
View File

@ -0,0 +1,14 @@
package model
// ResponseListStaffInfoByNotificationAction ...
type ResponseListStaffInfoByNotificationAction struct {
CreatedBys []ResponseStaffInfo `json:"CreatedBys"`
ApprovedBys []ResponseStaffInfo `json:"ApprovedBys"`
CancelledBys []ResponseStaffInfo `json:"CancelledBys"`
}
// ResponseStaffInfo ...
type ResponseStaffInfo struct {
ID string `json:"_id"`
Name string `json:"name"`
}

View File

@ -17,6 +17,7 @@ var prefixes = struct {
Withdraw string Withdraw string
Notification string Notification string
SocialPost string SocialPost string
Staff string
}{ }{
Communication: "communication", Communication: "communication",
Order: "order", Order: "order",
@ -34,4 +35,5 @@ var prefixes = struct {
Withdraw: "withdraw", Withdraw: "withdraw",
Notification: "notification", Notification: "notification",
SocialPost: "social_post", SocialPost: "social_post",
Staff: "staff",
} }

13
subject/staff.go Normal file
View File

@ -0,0 +1,13 @@
package subject
import "fmt"
func getStaffValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.Staff, val)
}
var Staff = struct {
GetListStaffInfoByNotificationAction string
}{
GetListStaffInfoByNotificationAction: getStaffValue("get_list_staff_info_by_notification_info"),
}