natsio/client/news.go

37 lines
887 B
Go
Raw Normal View History

2022-09-20 03:28:35 +00:00
package client
import (
"encoding/json"
"errors"
2022-10-10 04:11:39 +00:00
"git.selly.red/Selly-Modules/natsio"
"git.selly.red/Selly-Modules/natsio/model"
"git.selly.red/Selly-Modules/natsio/subject"
2022-09-20 03:28:35 +00:00
)
2022-09-20 03:56:45 +00:00
// News ...
type News struct{}
// GetNews ...
func GetNews() News {
return News{}
}
2022-09-20 03:28:35 +00:00
// GetProductNoticesByInventory ...
2022-09-20 03:56:45 +00:00
func (n News) GetProductNoticesByInventory(p model.GetProductNoticesByInventoryRequest) (*model.GetProductNoticesByInventoryResponse, error) {
2022-09-20 07:46:29 +00:00
msg, err := natsio.GetServer().Request(subject.News.GetProductNoticesByInventory, toBytes(p))
2022-09-20 03:28:35 +00:00
if err != nil {
return nil, err
}
var r struct {
Data *model.GetProductNoticesByInventoryResponse `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
}