Develop #22
			
				
			
		
		
		
	| 
						 | 
				
			
			@ -17,6 +17,7 @@ func GetLocation() Location {
 | 
			
		|||
	return Location{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetLocationByCode ...
 | 
			
		||||
func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*model.ResponseLocationAddress, error) {
 | 
			
		||||
	msg, err := natsio.GetServer().Request(subject.Location.GetLocationByCode, toBytes(payload))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
| 
						 | 
				
			
			@ -36,3 +37,70 @@ func (l Location) GetLocationByCode(payload model.LocationRequestPayload) (*mode
 | 
			
		|||
	}
 | 
			
		||||
	return r.Data, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetProvincesByCodes ... ...
 | 
			
		||||
func (l Location) GetProvincesByCodes(p model.ProvinceRequestPayload) (*model.LocationProvinceResponse, error) {
 | 
			
		||||
	msg, err := natsio.GetServer().Request(subject.Location.GetProvincesByCodes, toBytes(p))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var r struct {
 | 
			
		||||
		Data  *model.LocationProvinceResponse `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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetDistrictsByCodes ...
 | 
			
		||||
func (l Location) GetDistrictsByCodes(p model.DistrictRequestPayload) (*model.LocationDistrictResponse, error) {
 | 
			
		||||
	msg, err := natsio.GetServer().Request(subject.Location.GetDistrictsByCodes, toBytes(p))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	var r struct {
 | 
			
		||||
		Data  *model.LocationDistrictResponse `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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetWardsByCodes ...
 | 
			
		||||
func (l Location) GetWardsByCodes(p model.WardRequestPayload) (*model.LocationWardResponse, error) {
 | 
			
		||||
	msg, err := natsio.GetServer().Request(subject.Location.GetWardsByCodes, toBytes(p))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var r struct {
 | 
			
		||||
		Data  *model.LocationWardResponse `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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,3 +6,18 @@ type LocationRequestPayload struct {
 | 
			
		|||
	District int `json:"district"`
 | 
			
		||||
	Ward     int `json:"ward"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ProvinceRequestPayload ...
 | 
			
		||||
type ProvinceRequestPayload struct {
 | 
			
		||||
	Codes []int `json:"Codes"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DistrictRequestPayload ...
 | 
			
		||||
type DistrictRequestPayload struct {
 | 
			
		||||
	Codes []int `json:"Codes"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// WardRequestPayload ...
 | 
			
		||||
type WardRequestPayload struct {
 | 
			
		||||
	Codes []int `json:"Codes"`
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,3 +26,18 @@ type LocationWard struct {
 | 
			
		|||
	Name string `json:"name"`
 | 
			
		||||
	Code int    `json:"code"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LocationProvinceResponse ...
 | 
			
		||||
type LocationProvinceResponse struct {
 | 
			
		||||
	Province []LocationProvince `json:"province"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LocationDistrictResponse ...
 | 
			
		||||
type LocationDistrictResponse struct {
 | 
			
		||||
	District []LocationDistrict `json:"district"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LocationWardResponse ...
 | 
			
		||||
type LocationWardResponse struct {
 | 
			
		||||
	Ward []LocationWard `json:"ward"`
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,6 +8,12 @@ func getLocationValue(val string) string {
 | 
			
		|||
 | 
			
		||||
var Location = struct {
 | 
			
		||||
	GetLocationByCode   string
 | 
			
		||||
	GetProvincesByCodes string
 | 
			
		||||
	GetDistrictsByCodes string
 | 
			
		||||
	GetWardsByCodes     string
 | 
			
		||||
}{
 | 
			
		||||
	GetLocationByCode:   getLocationValue("get_location_warehouse"),
 | 
			
		||||
	GetProvincesByCodes: getLocationValue("get_provinces_warehouse"),
 | 
			
		||||
	GetDistrictsByCodes: getLocationValue("get_districts_warehouse"),
 | 
			
		||||
	GetWardsByCodes:     getLocationValue("get_wards_warehouse"),
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue