From 5c7b5bfd41a8fdac59d6f89d1f96615bc7956285 Mon Sep 17 00:00:00 2001 From: phuanbui Date: Fri, 7 Oct 2022 15:09:28 +0700 Subject: [PATCH] affliate-reconciliation get staff info --- client/staff.go | 35 +++++++++++++++++++++++++++++++++++ model/staff_request.go | 8 ++++++++ model/staff_response.go | 12 ++++++++++++ subject/config.go | 2 ++ subject/staff.go | 14 ++++++++++++++ 5 files changed, 71 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..72067be --- /dev/null +++ b/client/staff.go @@ -0,0 +1,35 @@ +package client + +import ( + "encoding/json" + "errors" + + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" +) + +type Staff struct{} + +func (s Staff) GetListStaffInfoByIDs(p model.GetListStaffInfoByIDsRequest) (*model.ResponseListStaffInfo, error) { + msg, err := natsio.GetServer().Request(subject.Staff.GetListStaffInfoByIDs, 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 +} diff --git a/model/staff_request.go b/model/staff_request.go new file mode 100644 index 0000000..4cb9107 --- /dev/null +++ b/model/staff_request.go @@ -0,0 +1,8 @@ +package model + +import "go.mongodb.org/mongo-driver/bson/primitive" + +// GetListStaffInfoByIDsRequest ... +type GetListStaffInfoByIDsRequest struct { + StaffIDs []primitive.ObjectID `json:"staffIds"` +} diff --git a/model/staff_response.go b/model/staff_response.go new file mode 100644 index 0000000..ffb3ba4 --- /dev/null +++ b/model/staff_response.go @@ -0,0 +1,12 @@ +package model + +// ResponseListStaffInfo ... +type ResponseListStaffInfo struct { + List []ResponseStaffInfo `json:"list"` +} + +// ResponseStaffInfo ... +type ResponseStaffInfo struct { + ID string `json:"_id"` + Name string `json:"name"` +} diff --git a/subject/config.go b/subject/config.go index 4a2f9f3..a17f54d 100644 --- a/subject/config.go +++ b/subject/config.go @@ -9,6 +9,7 @@ var prefixes = struct { Bank string Supplier string Seller string + Staff string }{ Communication: "communication", Order: "order", @@ -18,4 +19,5 @@ var prefixes = struct { Supplier: "supplier", Bank: "bank", Seller: "seller", + Staff: "staff", } diff --git a/subject/staff.go b/subject/staff.go new file mode 100644 index 0000000..0f0268a --- /dev/null +++ b/subject/staff.go @@ -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 { + GetListStaffInfoByIDs string +}{ + GetListStaffInfoByIDs: getStaffValue("get_list_staff_info_by_ids"), +}