natsio/client/campaign.go

37 lines
896 B
Go
Raw Permalink Normal View History

2022-11-24 02:06:48 +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"
)
// Campaign ...
type Campaign struct{}
2022-11-24 02:49:41 +00:00
// GetCampaign ...
func GetCampaign() Campaign {
return Campaign{}
}
2022-11-24 02:06:48 +00:00
// GetCampaignTransaction ...
func (c Campaign) GetCampaignTransaction(p model.GetCampaignTransactionsRequest) (*model.ResponseCampaignTransactionAll, error) {
msg, err := natsio.GetServer().Request(subject.Campaign.GetListCampaignTransactionAdminInfoByIDs, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseCampaignTransactionAll `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
}