update location
This commit is contained in:
parent
4a5adc610e
commit
021df099cc
|
@ -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"
|
||||||
|
|
||||||
|
type (
|
||||||
|
// ResponseLocationAddress ...
|
||||||
|
ResponseLocationAddress struct {
|
||||||
Province LocationProvince `json:"province"`
|
Province LocationProvince `json:"province"`
|
||||||
District LocationDistrict `json:"district"`
|
District LocationDistrict `json:"district"`
|
||||||
Ward LocationWard `json:"ward"`
|
Ward LocationWard `json:"ward"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocationProvince ...
|
// LocationProvince ...
|
||||||
type LocationProvince 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"`
|
||||||
|
}
|
||||||
|
|
||||||
// LocationDistrict ...
|
// LocationDistrict ...
|
||||||
type LocationDistrict 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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocationWard ...
|
// LocationWard ...
|
||||||
type LocationWard struct {
|
LocationWard 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 ...
|
// LocationProvinceResponse ...
|
||||||
type LocationProvinceResponse struct {
|
LocationProvinceResponse struct {
|
||||||
Provinces []LocationProvince `json:"provinces"`
|
Provinces []LocationProvince `json:"provinces"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocationDistrictResponse ...
|
// LocationDistrictResponse ...
|
||||||
type LocationDistrictResponse struct {
|
LocationDistrictResponse struct {
|
||||||
Districts []LocationDistrict `json:"districts"`
|
Districts []LocationDistrict `json:"districts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocationWardResponse ...
|
// LocationWardResponse ...
|
||||||
type LocationWardResponse struct {
|
LocationWardResponse struct {
|
||||||
Wards []LocationWard `json:"wards"`
|
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"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
|
@ -11,9 +11,27 @@ var Location = struct {
|
||||||
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