fix-holiday-product #137

Merged
trunglam merged 5 commits from fix-holiday-product into master 2023-01-31 03:31:49 +00:00
5 changed files with 416 additions and 70 deletions
Showing only changes of commit f4f15ea224 - Show all commits

View File

@ -19,7 +19,7 @@ func GetLocation() Location {
// GetLocationByCode ...
func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*model.ResponseLocationAddress, error) {
msg, err := natsio.GetServer().Request(subject.Location.GetLocationByCode, toBytes(payload))
msg, err := natsio.GetServer().Request(subject.Location.GetLocationByCodeFromLocationService, toBytes(payload))
if err != nil {
return nil, err
}
@ -28,7 +28,7 @@ func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*mode
Data *model.ResponseLocationAddress `json:"data"`
Error string `json:"error"`
}
if err := json.Unmarshal(msg.Data, &r); err != nil {
if err = json.Unmarshal(msg.Data, &r); err != nil {
return nil, err
}
@ -38,19 +38,19 @@ func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*mode
return r.Data, nil
}
// GetProvincesByCodes ... ...
// GetProvincesByCodes ...
func (l Location) GetProvincesByCodes(p model.ProvinceRequestPayload) (*model.LocationProvinceResponse, error) {
msg, err := natsio.GetServer().Request(subject.Location.GetProvincesByCodes, toBytes(p))
msg, err := natsio.GetServer().Request(subject.Location.GetProvincesByCodesFromLocationService, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.LocationProvinceResponse `json:"data"'`
Data *model.LocationProvinceResponse `json:"data"`
Error string `json:"error"`
}
if err := json.Unmarshal(msg.Data, &r); err != nil {
if err = json.Unmarshal(msg.Data, &r); err != nil {
return nil, err
}
@ -62,7 +62,7 @@ func (l Location) GetProvincesByCodes(p model.ProvinceRequestPayload) (*model.Lo
// GetDistrictsByCodes ...
func (l Location) GetDistrictsByCodes(p model.DistrictRequestPayload) (*model.LocationDistrictResponse, error) {
msg, err := natsio.GetServer().Request(subject.Location.GetDistrictsByCodes, toBytes(p))
msg, err := natsio.GetServer().Request(subject.Location.GetDistrictsByCodesFromLocationService, toBytes(p))
if err != nil {
return nil, err
}
@ -71,7 +71,7 @@ func (l Location) GetDistrictsByCodes(p model.DistrictRequestPayload) (*model.Lo
Error string `json:"error"`
}
if err := json.Unmarshal(msg.Data, &r); err != nil {
if err = json.Unmarshal(msg.Data, &r); err != nil {
return nil, err
}
@ -84,7 +84,7 @@ func (l Location) GetDistrictsByCodes(p model.DistrictRequestPayload) (*model.Lo
// GetWardsByCodes ...
func (l Location) GetWardsByCodes(p model.WardRequestPayload) (*model.LocationWardResponse, error) {
msg, err := natsio.GetServer().Request(subject.Location.GetWardsByCodes, toBytes(p))
msg, err := natsio.GetServer().Request(subject.Location.GetWardsByCodesFromLocationService, toBytes(p))
if err != nil {
return nil, err
}
@ -94,7 +94,7 @@ func (l Location) GetWardsByCodes(p model.WardRequestPayload) (*model.LocationWa
Error string `json:"error"`
}
if err := json.Unmarshal(msg.Data, &r); err != nil {
if err = json.Unmarshal(msg.Data, &r); err != nil {
return nil, err
}
@ -104,3 +104,211 @@ func (l Location) GetWardsByCodes(p model.WardRequestPayload) (*model.LocationWa
return r.Data, nil
}
// 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
}

View File

@ -20,3 +20,26 @@ type ActionBy struct {
ID string `json:"id"`
Name string `json:"name"`
}
// RequestCondition ...
type RequestCondition struct {
Code int `json:"code"`
Codes []int `json:"codes"`
DistrictCode int `json:"districtCode"`
ProvinceCode int `json:"provinceCode"`
Slug string `json:"slug"`
OldSlug string `json:"oldSlug"`
Slugs []string `json:"slugs"`
OldSlugs []string `json:"oldSlugs"`
DistrictSlug string `json:"districtSlug"`
ProvinceSlug string `json:"provinceSlug"`
Keyword string `json:"keyword"`
Region string `json:"region"`
Page int64 `json:"page"`
Limit int64 `json:"limit"`
}

View File

@ -1,23 +1,66 @@
package model
// LocationRequestPayload ...
type LocationRequestPayload struct {
type (
// LocationRequestPayload ...
LocationRequestPayload struct {
Province int `json:"province"`
District int `json:"district"`
Ward int `json:"ward"`
}
}
// ProvinceRequestPayload ...
type ProvinceRequestPayload struct {
// ProvinceRequestPayload ...
ProvinceRequestPayload struct {
Codes []int `json:"codes"`
}
}
// DistrictRequestPayload ...
type DistrictRequestPayload struct {
// ProvinceRequestCondition ...
ProvinceRequestCondition struct {
Code int `json:"code"`
Codes []int `json:"codes"`
}
Slug string `json:"slug"`
Slugs []string `json:"slugs"`
Keyword string `json:"keyword"`
Region string `json:"region"`
}
// WardRequestPayload ...
type WardRequestPayload struct {
// DistrictRequestPayload ...
DistrictRequestPayload struct {
Codes []int `json:"codes"`
}
}
// DistrictRequestCondition ...
DistrictRequestCondition struct {
Code int `json:"code"`
Codes []int `json:"codes"`
ProvinceCode int `json:"provinceCode"`
Slug string `json:"slug"`
ProvinceSlug string `json:"provinceSlug"`
Keyword string `json:"keyword"`
}
// WardRequestPayload ...
WardRequestPayload struct {
Codes []int `json:"codes"`
}
// WardRequestCondition ...
WardRequestCondition struct {
Code int `json:"code"`
Codes []int `json:"codes"`
DistrictCode int `json:"districtCode"`
ProvinceCode int `json:"provinceCode"`
Slug string `json:"slug"`
DistrictSlug string `json:"districtSlug"`
ProvinceSlug string `json:"provinceSlug"`
Keyword string `json:"keyword"`
}
// ProvinceDistinctWithField ...
ProvinceDistinctWithField struct {
Conditions struct {
Region string `json:"region"`
} `json:"conditions"`
Field string `json:"filed"`
}
)

View File

@ -1,43 +1,87 @@
package model
type ResponseLocationAddress struct {
type (
// ResponseLocationAddress ...
ResponseLocationAddress struct {
Province LocationProvince `json:"province"`
District LocationDistrict `json:"district"`
Ward LocationWard `json:"ward"`
}
}
// LocationProvince ...
type LocationProvince struct {
// LocationProvince ...
LocationProvince struct {
ID string `json:"id"`
Name string `json:"name"`
Code int `json:"code"`
}
Slug string `json:"slug"`
RegionCode string `json:"regionCode"`
MainRegionCode string `json:"mainRegionCode"`
}
// LocationDistrict ...
type LocationDistrict struct {
// LocationDistrict ...
LocationDistrict struct {
ID string `json:"id"`
Name string `json:"name"`
Code int `json:"code"`
}
Slug string `json:"slug"`
}
// LocationWard ...
type LocationWard struct {
// LocationWard ...
LocationWard struct {
ID string `json:"id"`
Name string `json:"name"`
Code int `json:"code"`
}
Slug string `json:"slug"`
}
// LocationProvinceResponse ...
type LocationProvinceResponse struct {
// LocationProvinceResponse ...
LocationProvinceResponse struct {
Provinces []LocationProvince `json:"provinces"`
}
}
// LocationDistrictResponse ...
type LocationDistrictResponse struct {
// LocationDistrictResponse ...
LocationDistrictResponse struct {
Districts []LocationDistrict `json:"districts"`
}
}
// LocationWardResponse ...
type LocationWardResponse struct {
// LocationWardResponse ...
LocationWardResponse struct {
Wards []LocationWard `json:"wards"`
}
}
// LocationProvinceDetailResponse ...
LocationProvinceDetailResponse struct {
ID string `json:"_id"`
Name string `json:"name"`
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"`
}
// LocationDistrictDetailResponse ...
LocationDistrictDetailResponse struct {
ID string `json:"_id"`
Name string `json:"name"`
OldSlugs []string `json:"oldSlugs"`
Slug string `json:"slug"`
Code int `json:"code"`
ProvinceCode int `json:"provinceCode"`
Area int `json:"area"`
TotalWards int `json:"totalWards"`
}
// LocationWardDetailResponse ...
LocationWardDetailResponse struct {
ID string `json:"_id"`
Name string `json:"name"`
OldSlugs []string `json:"oldSlugs"`
Slug string `json:"slug"`
Code int `json:"code"`
DistrictCode int `json:"districtCode"`
ProvinceCode int `json:"provinceCode"`
}
)

View File

@ -8,12 +8,40 @@ func getLocationValue(val string) string {
var Location = struct {
GetLocationByCode string
GetLocationByCodeFromLocationService string
GetProvincesByCodes string
GetProvincesByCodesFromLocationService string
GetDistrictsByCodes string
GetDistrictsByCodesFromLocationService string
GetWardsByCodes string
GetWardsByCodesFromLocationService string
GetProvinceByCondition string
GetProvincesByCondition string
GetDistrictByCondition string
GetDistrictsByCondition string
GetWardByCondition string
GetWardsByCondition string
CountProvinceByCondition string
CountDistrictByCondition string
CountWardByCondition string
ProvinceDistinctWithField string
}{
GetLocationByCode: getLocationValue("get_location_warehouse"),
GetLocationByCodeFromLocationService: getLocationValue("get_location_warehouse_from_location_service"),
GetProvincesByCodes: getLocationValue("get_provinces_by_codes"),
GetProvincesByCodesFromLocationService: getLocationValue("get_provinces_by_codes_from_location_service"),
GetDistrictsByCodes: getLocationValue("get_districts_by_codes"),
GetDistrictsByCodesFromLocationService: getLocationValue("get_districts_by_codes_from_location_service"),
GetWardsByCodes: getLocationValue("get_wards_by_codes"),
GetWardsByCodesFromLocationService: getLocationValue("get_wards_by_codes_from_location_service"),
GetProvinceByCondition: getLocationValue("get_province_by_condition"),
GetProvincesByCondition: getLocationValue("get_provinces_by_condition"),
GetDistrictByCondition: getLocationValue("get_district_by_condition"),
GetDistrictsByCondition: getLocationValue("get_districts_byCondition"),
GetWardByCondition: getLocationValue("get_ward_by_condition"),
GetWardsByCondition: getLocationValue("get_wards_by_condition"),
CountProvinceByCondition: getLocationValue("count_province_by_condition"),
CountDistrictByCondition: getLocationValue("count_district_by_condition"),
CountWardByCondition: getLocationValue("count_ward_by_condition"),
ProvinceDistinctWithField: getLocationValue("province_distinct_with_field"),
}