diff --git a/client/staff.go b/client/staff.go new file mode 100644 index 0000000..7bcd91d --- /dev/null +++ b/client/staff.go @@ -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 + +} diff --git a/model/staff_request.go b/model/staff_request.go new file mode 100644 index 0000000..904f617 --- /dev/null +++ b/model/staff_request.go @@ -0,0 +1,8 @@ +package model + +// GetListStaffByNotificationActionRequest ... +type GetListStaffByNotificationActionRequest struct { + CreatedBys []string `json:"createdBys"` + ApprovedBys []string `json:"approvedBys"` + CancelledBys []string `json:"cancelledBys"` +} diff --git a/model/staff_response.go b/model/staff_response.go new file mode 100644 index 0000000..cd471a2 --- /dev/null +++ b/model/staff_response.go @@ -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"` +} diff --git a/subject/config.go b/subject/config.go index 8837975..6988929 100644 --- a/subject/config.go +++ b/subject/config.go @@ -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", } diff --git a/subject/staff.go b/subject/staff.go new file mode 100644 index 0000000..0cdbcf0 --- /dev/null +++ b/subject/staff.go @@ -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"), +}