add get segment info #70
|
@ -0,0 +1,40 @@
|
|||
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{}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package model
|
||||
|
||||
// GetListSegmentRequest ...
|
||||
type GetListSegmentRequest struct {
|
||||
SegmentIds []string `json:"segmentIds"`
|
||||
}
|
|
@ -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"`
|
||||
}
|
|
@ -18,6 +18,7 @@ var prefixes = struct {
|
|||
Notification string
|
||||
SocialPost string
|
||||
Staff string
|
||||
Segment string
|
||||
}{
|
||||
Communication: "communication",
|
||||
Order: "order",
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package subject
|
||||
|
||||
import "fmt"
|
||||
|
||||
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"),
|
||||
}
|
Loading…
Reference in New Issue