affliate-reconciliation get staff info #40

Closed
anbuiselly wants to merge 1 commits from feature/affiliate-reconciliation into develop
5 changed files with 71 additions and 0 deletions

35
client/staff.go Normal file
View File

@ -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
}

8
model/staff_request.go Normal file
View File

@ -0,0 +1,8 @@
package model
import "go.mongodb.org/mongo-driver/bson/primitive"
// GetListStaffInfoByIDsRequest ...
type GetListStaffInfoByIDsRequest struct {
StaffIDs []primitive.ObjectID `json:"staffIds"`
}

12
model/staff_response.go Normal file
View File

@ -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"`
}

View File

@ -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",
}

14
subject/staff.go Normal file
View File

@ -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"),
}