2022-08-26 10:15:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/Selly-Modules/natsio"
|
|
|
|
"github.com/Selly-Modules/natsio/model"
|
|
|
|
"github.com/Selly-Modules/natsio/subject"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Location ...
|
|
|
|
type Location struct{}
|
|
|
|
|
|
|
|
// GetLocation ...
|
|
|
|
func GetLocation() Location {
|
|
|
|
return Location{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*model.ResponseLocationAddress, error) {
|
2022-08-26 10:36:02 +00:00
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.GetLocationByCode, toBytes(payload))
|
2022-08-26 10:15:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
|
|
|
Data *model.ResponseLocationAddress `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
|
|
|
|
}
|