diff --git a/client/location.go b/client/location.go index bd7333d..fa984bb 100644 --- a/client/location.go +++ b/client/location.go @@ -38,6 +38,27 @@ func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*mode return r.Data, nil } +// GetLocationByWardCode ... +func (l Location) GetLocationByWardCode(payload model.RequestCondition) (*model.ResponseLocationAddress, error) { + msg, err := natsio.GetServer().Request(subject.Location.GetLocationByWardCode, toBytes(payload)) + 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 +} + // GetProvincesByCodes ... func (l Location) GetProvincesByCodes(p model.ProvinceRequestPayload) (*model.LocationProvinceResponse, error) { msg, err := natsio.GetServer().Request(subject.Location.GetProvincesByCodesFromLocationService, toBytes(p)) diff --git a/subject/location.go b/subject/location.go index df2117c..4b730b2 100644 --- a/subject/location.go +++ b/subject/location.go @@ -9,6 +9,7 @@ func getLocationValue(val string) string { var Location = struct { GetLocationByCode string GetLocationByCodeFromLocationService string + GetLocationByWardCode string GetProvincesByCodes string GetProvincesByCodesFromLocationService string GetDistrictsByCodes string @@ -28,6 +29,7 @@ var Location = struct { }{ GetLocationByCode: getLocationValue("get_location_warehouse"), GetLocationByCodeFromLocationService: getLocationValue("get_location_warehouse_from_location_service"), + GetLocationByWardCode: getLocationValue("get_location_by_ward_code"), GetProvincesByCodes: getLocationValue("get_provinces_by_codes"), GetProvincesByCodesFromLocationService: getLocationValue("get_provinces_by_codes_from_location_service"), GetDistrictsByCodes: getLocationValue("get_districts_by_codes"),