mergeDev/campaign #73
|
@ -0,0 +1,180 @@
|
||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"github.com/Selly-Modules/natsio"
|
||||||
|
"github.com/Selly-Modules/natsio/model"
|
||||||
|
"github.com/Selly-Modules/natsio/subject"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FindOneProvinceByCondition ...
|
||||||
|
func (l Location) FindOneProvinceByCondition(p model.FindOneCondition) (*model.LocationProvinceDetailResponse, error) {
|
||||||
|
msg, err := natsio.GetServer().Request(subject.Location.FindOneProvinceByCondition, bsonToBytes(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
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindOneDistrictByCondition ...
|
||||||
|
func (l Location) FindOneDistrictByCondition(p model.FindOneCondition) (*model.LocationDistrictDetailResponse, error) {
|
||||||
|
msg, err := natsio.GetServer().Request(subject.Location.FindOneDistrictByCondition, bsonToBytes(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
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindOneWardByCondition ...
|
||||||
|
func (l Location) FindOneWardByCondition(p model.FindOneCondition) (*model.LocationWardDetailResponse, error) {
|
||||||
|
msg, err := natsio.GetServer().Request(subject.Location.FindOneWardByCondition, bsonToBytes(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
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindProvinceByCondition ...
|
||||||
|
func (l Location) FindProvinceByCondition(p model.FindWithCondition) ([]*model.LocationProvinceDetailResponse, error) {
|
||||||
|
msg, err := natsio.GetServer().Request(subject.Location.FindProvinceByCondition, bsonToBytes(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
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindDistrictByCondition ...
|
||||||
|
func (l Location) FindDistrictByCondition(p model.FindWithCondition) ([]*model.LocationDistrictDetailResponse, error) {
|
||||||
|
msg, err := natsio.GetServer().Request(subject.Location.FindDistrictByCondition, bsonToBytes(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
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindWardByCondition ...
|
||||||
|
func (l Location) FindWardByCondition(p model.FindWithCondition) ([]*model.LocationWardDetailResponse, error) {
|
||||||
|
msg, err := natsio.GetServer().Request(subject.Location.FindWardByCondition, bsonToBytes(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.FindWithCondition) (int64, error) {
|
||||||
|
msg, err := natsio.GetServer().Request(subject.Location.CountProvinceByCondition, bsonToBytes(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.FindWithCondition) (int64, error) {
|
||||||
|
msg, err := natsio.GetServer().Request(subject.Location.CountDistrictByCondition, bsonToBytes(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.FindWithCondition) (int64, error) {
|
||||||
|
msg, err := natsio.GetServer().Request(subject.Location.CountWardByCondition, bsonToBytes(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
|
||||||
|
}
|
|
@ -1,43 +1,93 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
type ResponseLocationAddress struct {
|
import "time"
|
||||||
Province LocationProvince `json:"province"`
|
|
||||||
District LocationDistrict `json:"district"`
|
|
||||||
Ward LocationWard `json:"ward"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LocationProvince ...
|
type (
|
||||||
type LocationProvince struct {
|
// ResponseLocationAddress ...
|
||||||
ID string `json:"id"`
|
ResponseLocationAddress struct {
|
||||||
Name string `json:"name"`
|
Province LocationProvince `json:"province"`
|
||||||
Code int `json:"code"`
|
District LocationDistrict `json:"district"`
|
||||||
}
|
Ward LocationWard `json:"ward"`
|
||||||
|
}
|
||||||
|
|
||||||
// LocationDistrict ...
|
// LocationProvince ...
|
||||||
type LocationDistrict struct {
|
LocationProvince struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
}
|
RegionCode string `json:"regionCode"`
|
||||||
|
MainRegionCode string `json:"mainRegionCode"`
|
||||||
|
}
|
||||||
|
|
||||||
// LocationWard ...
|
// LocationDistrict ...
|
||||||
type LocationWard struct {
|
LocationDistrict struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocationProvinceResponse ...
|
// LocationWard ...
|
||||||
type LocationProvinceResponse struct {
|
LocationWard struct {
|
||||||
Provinces []LocationProvince `json:"provinces"`
|
ID string `json:"id"`
|
||||||
}
|
Name string `json:"name"`
|
||||||
|
Code int `json:"code"`
|
||||||
|
}
|
||||||
|
|
||||||
// LocationDistrictResponse ...
|
// LocationProvinceResponse ...
|
||||||
type LocationDistrictResponse struct {
|
LocationProvinceResponse struct {
|
||||||
Districts []LocationDistrict `json:"districts"`
|
Provinces []LocationProvince `json:"provinces"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocationWardResponse ...
|
// LocationDistrictResponse ...
|
||||||
type LocationWardResponse struct {
|
LocationDistrictResponse struct {
|
||||||
Wards []LocationWard `json:"wards"`
|
Districts []LocationDistrict `json:"districts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LocationWardResponse ...
|
||||||
|
LocationWardResponse struct {
|
||||||
|
Wards []LocationWard `json:"wards"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LocationProvinceDetailResponse ...
|
||||||
|
LocationProvinceDetailResponse struct {
|
||||||
|
ID string `json:"_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
SearchString string `json:"searchString"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
Code int `json:"code"`
|
||||||
|
CountryCode string `json:"countryCode"`
|
||||||
|
RegionCode string `json:"regionCode"`
|
||||||
|
MainRegionCode string `json:"mainRegionCode"`
|
||||||
|
TotalDistricts int `json:"totalDistricts"`
|
||||||
|
TotalWards int `json:"totalWards"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LocationDistrictDetailResponse ...
|
||||||
|
LocationDistrictDetailResponse struct {
|
||||||
|
ID string `json:"_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
SearchString string `json:"searchString"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
Code int `json:"code"`
|
||||||
|
ProvinceCode int `json:"provinceCode"`
|
||||||
|
Area int `json:"area"`
|
||||||
|
TotalWards int `json:"totalWards"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LocationWardDetailResponse ...
|
||||||
|
LocationWardDetailResponse struct {
|
||||||
|
ID string `json:"_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
SearchString string `json:"searchString"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
Code int `json:"code"`
|
||||||
|
DistrictCode int `json:"districtCode"`
|
||||||
|
ProvinceCode int `json:"provinceCode"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
|
@ -7,13 +7,31 @@ func getLocationValue(val string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
var Location = struct {
|
var Location = struct {
|
||||||
GetLocationByCode string
|
GetLocationByCode string
|
||||||
GetProvincesByCodes string
|
GetProvincesByCodes string
|
||||||
GetDistrictsByCodes string
|
GetDistrictsByCodes string
|
||||||
GetWardsByCodes string
|
GetWardsByCodes string
|
||||||
|
FindOneProvinceByCondition string
|
||||||
|
FindOneDistrictByCondition string
|
||||||
|
FindOneWardByCondition string
|
||||||
|
FindProvinceByCondition string
|
||||||
|
FindDistrictByCondition string
|
||||||
|
FindWardByCondition string
|
||||||
|
CountProvinceByCondition string
|
||||||
|
CountDistrictByCondition string
|
||||||
|
CountWardByCondition string
|
||||||
}{
|
}{
|
||||||
GetLocationByCode: getLocationValue("get_location_warehouse"),
|
GetLocationByCode: getLocationValue("get_location_warehouse"),
|
||||||
GetProvincesByCodes: getLocationValue("get_provinces_by_codes"),
|
GetProvincesByCodes: getLocationValue("get_provinces_by_codes"),
|
||||||
GetDistrictsByCodes: getLocationValue("get_districts_by_codes"),
|
GetDistrictsByCodes: getLocationValue("get_districts_by_codes"),
|
||||||
GetWardsByCodes: getLocationValue("get_wards_by_codes"),
|
GetWardsByCodes: getLocationValue("get_wards_by_codes"),
|
||||||
|
FindOneProvinceByCondition: getLocationValue("find_one_province_by_condition"),
|
||||||
|
FindOneDistrictByCondition: getLocationValue("find_one_district_by_condition"),
|
||||||
|
FindOneWardByCondition: getLocationValue("find_one_ward_by_condition"),
|
||||||
|
FindProvinceByCondition: getLocationValue("find_province_by_condition"),
|
||||||
|
FindDistrictByCondition: getLocationValue("find_district_by_condition"),
|
||||||
|
FindWardByCondition: getLocationValue("find_ward_by_condition"),
|
||||||
|
CountProvinceByCondition: getLocationValue("count_province_by_condition"),
|
||||||
|
CountDistrictByCondition: getLocationValue("count_district_by_condition"),
|
||||||
|
CountWardByCondition: getLocationValue("count_ward_by_condition"),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue