Merge pull request 'get staff by notification action' (#64) from feaure/staff-getinfo into develop

Reviewed-on: #64
This commit is contained in:
phuanbui 2022-11-18 09:23:35 +00:00
commit d891c3a051
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
Notification string
SocialPost string
Staff string
}{
Communication: "communication",
Order: "order",
@ -34,4 +35,5 @@ var prefixes = struct {
Withdraw: "withdraw",
Notification: "notification",
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"),
}