Merge pull request 'add get segment info' (#70) from feaure/staff-getinfo into develop

Reviewed-on: #70
This commit is contained in:
phuanbui 2022-11-21 22:44:59 +00:00
commit 913c762897
5 changed files with 75 additions and 0 deletions

41
client/segment.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"
)
// Segment ...
type Segment struct{}
// GetSegment ...
func GetSegment() Segment {
return Segment{}
}
// GetListSegmentInfoByIds ...
func (s Segment) GetListSegmentInfoByIds(p model.GetListSegmentRequest) (*model.ResponseListSegmentInfo, error) {
msg, err := natsio.GetServer().Request(subject.Segment.GetListSegmentInfo, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseListSegmentInfo `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
}

6
model/segment_request.go Normal file
View File

@ -0,0 +1,6 @@
package model
// GetListSegmentRequest ...
type GetListSegmentRequest struct {
SegmentIds []string `json:"segmentIds"`
}

12
model/segment_response.go Normal file
View File

@ -0,0 +1,12 @@
package model
// ResponseSegmentInfo ...
type ResponseSegmentInfo struct {
ID string `json:"_id"`
Name string `json:"name"`
}
// ResponseListSegmentInfo ...
type ResponseListSegmentInfo struct {
Segments []ResponseSegmentInfo `json:"segments"`
}

View File

@ -18,6 +18,7 @@ var prefixes = struct {
Notification string
SocialPost string
Staff string
Segment string
}{
Communication: "communication",
Order: "order",

15
subject/segment.go Normal file
View File

@ -0,0 +1,15 @@
package subject
import "fmt"
// getSegmentValue ...
func getSegmentValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.Segment, val)
}
// Segment ...
var Segment = struct {
GetListSegmentInfo string
}{
GetListSegmentInfo: getSegmentValue("get_list_segment_info"),
}