natsio/client/social_post.go

66 lines
1.5 KiB
Go
Raw Normal View History

2022-11-14 07:45:26 +00:00
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"
)
// SocialPost ...
type SocialPost struct{}
// GetSocialPost ...
func GetSocialPost() SocialPost {
return SocialPost{}
}
// GetListSocialPostAppInfoByIDs ...
2022-11-14 08:11:04 +00:00
func (s SocialPost) GetListSocialPostAppInfoByIDs(p model.GetListSocialPostAppByIDsRequest) (*model.ResponseListSocialPostAppInfo, error) {
2022-11-14 07:45:26 +00:00
msg, err := natsio.GetServer().Request(subject.SocialPost.GetListSocialPostAppInfoByIDs, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseListSocialPostAppInfo `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
}
2022-11-16 09:38:41 +00:00
// GetBriefDetailSocialPostAdminByIDsRequest ...
2022-11-17 02:27:45 +00:00
func (s SocialPost) GetBriefDetailSocialPostAdminByIDsRequest(p model.GetBriefInfoSocialPostAdminByIDsRequest) (*model.ResponseListSocialPostAdminInfo, error) {
2022-11-16 10:21:37 +00:00
msg, err := natsio.GetServer().Request(subject.SocialPost.GetBriefInfoSocialPostAdminByIDs, toBytes(p))
2022-11-16 09:38:41 +00:00
if err != nil {
return nil, err
}
var r struct {
2022-11-17 02:27:45 +00:00
Data *model.ResponseListSocialPostAdminInfo `json:"data"`
Error string `json:"error"`
2022-11-16 09:38:41 +00:00
}
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
}