2022-08-26 10:15:49 +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-08-26 10:15:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Location ...
|
|
|
|
type Location struct{}
|
|
|
|
|
|
|
|
// GetLocation ...
|
|
|
|
func GetLocation() Location {
|
|
|
|
return Location{}
|
|
|
|
}
|
|
|
|
|
2022-09-07 07:01:29 +00:00
|
|
|
// GetLocationByCode ...
|
2022-08-26 10:15:49 +00:00
|
|
|
func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*model.ResponseLocationAddress, error) {
|
2023-01-17 10:22:28 +00:00
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.GetLocationByCodeFromLocationService, 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"`
|
|
|
|
}
|
2023-01-17 09:29:47 +00:00
|
|
|
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
2022-08-26 10:15:49 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.Error != "" {
|
|
|
|
return nil, errors.New(r.Error)
|
|
|
|
}
|
|
|
|
return r.Data, nil
|
|
|
|
}
|
2022-09-07 07:01:29 +00:00
|
|
|
|
2023-01-17 09:29:47 +00:00
|
|
|
// GetProvincesByCodes ...
|
2022-09-07 07:01:29 +00:00
|
|
|
func (l Location) GetProvincesByCodes(p model.ProvinceRequestPayload) (*model.LocationProvinceResponse, error) {
|
2023-01-17 10:22:28 +00:00
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.GetProvincesByCodesFromLocationService, toBytes(p))
|
2022-09-07 07:01:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
2023-01-17 09:29:47 +00:00
|
|
|
Data *model.LocationProvinceResponse `json:"data"`
|
2022-09-07 07:01:29 +00:00
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
|
2023-01-17 09:29:47 +00:00
|
|
|
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
2022-09-07 07:01:29 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.Error != "" {
|
|
|
|
return nil, errors.New(r.Error)
|
|
|
|
}
|
|
|
|
return r.Data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDistrictsByCodes ...
|
|
|
|
func (l Location) GetDistrictsByCodes(p model.DistrictRequestPayload) (*model.LocationDistrictResponse, error) {
|
2023-01-17 10:22:28 +00:00
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.GetDistrictsByCodesFromLocationService, toBytes(p))
|
2022-09-07 07:01:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r struct {
|
|
|
|
Data *model.LocationDistrictResponse `json:"data"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
|
2023-01-17 09:29:47 +00:00
|
|
|
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
2022-09-07 07:01:29 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.Error != "" {
|
|
|
|
return nil, errors.New(r.Error)
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.Data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetWardsByCodes ...
|
|
|
|
func (l Location) GetWardsByCodes(p model.WardRequestPayload) (*model.LocationWardResponse, error) {
|
2023-01-17 10:22:28 +00:00
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.GetWardsByCodesFromLocationService, toBytes(p))
|
2022-09-07 07:01:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
|
|
|
Data *model.LocationWardResponse `json:"data"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
|
2023-01-17 09:29:47 +00:00
|
|
|
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
2022-09-07 07:01:29 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.Error != "" {
|
|
|
|
return nil, errors.New(r.Error)
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.Data, nil
|
|
|
|
}
|
2023-01-17 09:29:47 +00:00
|
|
|
|
|
|
|
// GetProvinceByCondition ...
|
|
|
|
func (l Location) GetProvinceByCondition(p model.RequestCondition) (*model.LocationProvinceDetailResponse, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.GetProvinceByCondition, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
|
|
|
Data *model.LocationProvinceDetailResponse `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
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetProvincesByCondition ...
|
|
|
|
func (l Location) GetProvincesByCondition(p model.RequestCondition) ([]*model.LocationProvinceDetailResponse, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.GetProvincesByCondition, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
|
|
|
Data []*model.LocationProvinceDetailResponse `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
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDistrictByCondition ...
|
|
|
|
func (l Location) GetDistrictByCondition(p model.RequestCondition) (*model.LocationDistrictDetailResponse, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.GetDistrictByCondition, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
|
|
|
Data *model.LocationDistrictDetailResponse `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
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDistrictsByCondition ...
|
|
|
|
func (l Location) GetDistrictsByCondition(p model.RequestCondition) ([]*model.LocationDistrictDetailResponse, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.GetDistrictsByCondition, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
|
|
|
Data []*model.LocationDistrictDetailResponse `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
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetWardByCondition ...
|
|
|
|
func (l Location) GetWardByCondition(p model.RequestCondition) (*model.LocationWardDetailResponse, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.GetWardByCondition, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
|
|
|
Data *model.LocationWardDetailResponse `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
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetWardsByCondition ...
|
|
|
|
func (l Location) GetWardsByCondition(p model.RequestCondition) ([]*model.LocationWardDetailResponse, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.GetWardsByCondition, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var r struct {
|
|
|
|
Data []*model.LocationWardDetailResponse `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
|
|
|
|
}
|
|
|
|
|
|
|
|
// CountProvinceByCondition ...
|
|
|
|
func (l Location) CountProvinceByCondition(p model.RequestCondition) (int64, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.CountProvinceByCondition, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
var r struct {
|
|
|
|
Data int64 `json:"data"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
if r.Error != "" {
|
|
|
|
return 0, errors.New(r.Error)
|
|
|
|
}
|
|
|
|
return r.Data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CountDistrictByCondition ...
|
|
|
|
func (l Location) CountDistrictByCondition(p model.RequestCondition) (int64, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.CountDistrictByCondition, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
var r struct {
|
|
|
|
Data int64 `json:"data"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
if r.Error != "" {
|
|
|
|
return 0, errors.New(r.Error)
|
|
|
|
}
|
|
|
|
return r.Data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CountWardByCondition ...
|
|
|
|
func (l Location) CountWardByCondition(p model.RequestCondition) (int64, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.CountWardByCondition, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
var r struct {
|
|
|
|
Data int64 `json:"data"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
if r.Error != "" {
|
|
|
|
return 0, errors.New(r.Error)
|
|
|
|
}
|
|
|
|
return r.Data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DistinctWithField ...
|
|
|
|
func (l Location) DistinctWithField(p model.ProvinceDistinctWithField) ([]interface{}, error) {
|
|
|
|
msg, err := natsio.GetServer().Request(subject.Location.ProvinceDistinctWithField, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r struct {
|
|
|
|
Data []interface{} `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
|
|
|
|
}
|