From 8cceae74ef96afc69b7ac7361376e383f2ccf5ea Mon Sep 17 00:00:00 2001 From: anbuiselly <105765792+anbuiselly@users.noreply.github.com> Date: Fri, 18 Nov 2022 16:22:17 +0700 Subject: [PATCH] get staff by notification action --- client/staff.go | 41 +++++++++++++++++++++++++++++++++++++++++ model/staff_request.go | 8 ++++++++ model/staff_response.go | 14 ++++++++++++++ subject/config.go | 2 ++ subject/staff.go | 13 +++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 client/staff.go create mode 100644 model/staff_request.go create mode 100644 model/staff_response.go create mode 100644 subject/staff.go 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"), +}