Skip to content

Commit

Permalink
update: getting state from stateCodes
Browse files Browse the repository at this point in the history
  • Loading branch information
rzp-Piyush committed Nov 18, 2024
1 parent 2db4fe8 commit 78379db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func (r *CountrySubdivisions) GetCountryName() string {
func (r *CountrySubdivisions) GetStates() map[string]State {
return r.States
}
func (r *CountrySubdivisions) GetStateByStateCode(code string) (State, bool) {
if _, exists := r.States[code]; exists {
return r.States[code], true
}
return State{}, false
}

// GetCountrySubdivisions retrieves subdivision information for a specific country code.
func GetCountrySubdivisions(code string) CountrySubdivisions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ func GetCountryZipCodeDetails(code string) *PinCodeData {
func GetStatesFromZipCode(zipCode string, countryCode string) []country_subdivisions.State {
pinCodeData := GetCountryZipCodeDetails(countryCode)
subdivisions := country_subdivisions.GetCountrySubdivisions(countryCode)
subDivisionStates := subdivisions.GetStates()
var states []country_subdivisions.State
for _, stateCode := range pinCodeData.pinCodeToDetails[zipCode].StateCodes {
if _, exists := subDivisionStates[stateCode]; exists {
states = append(states, subdivisions.GetStates()[stateCode])
if state, exists := subdivisions.GetStateByStateCode(stateCode); exists {
states = append(states, state)
}
}
return states
Expand Down

0 comments on commit 78379db

Please sign in to comment.