ntgvision maps zips to states then does same query

Bel LaPointe 2022-01-27 18:14:49 -07:00
parent db289cb5c8
commit d2cf8c74a2
1 changed files with 17 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import (
"io/ioutil" "io/ioutil"
"local/truckstop/config" "local/truckstop/config"
"local/truckstop/logtr" "local/truckstop/logtr"
"local/truckstop/zip"
"net/http" "net/http"
"time" "time"
) )
@ -188,7 +189,22 @@ func (ntg NTGVision) searchJob(id int64) (ntgVisionJobInfo, error) {
} }
func (ntg NTGVision) SearchZips(zips []string) ([]Job, error) { func (ntg NTGVision) SearchZips(zips []string) ([]Job, error) {
return nil, errors.New("not impl: ntg search zips") radius := config.Get().Brokers.RadiusMiles
statesm := map[string]struct{}{}
for _, z := range zips {
somestates := zip.GetStatesWithin(zip.Get(z), radius)
for _, state := range somestates {
statesm[state] = struct{}{}
}
}
states := make([]config.State, 0, len(statesm))
for state := range statesm {
states = append(states, config.State(state))
}
if len(states) == 0 {
return nil, fmt.Errorf("failed to map zipcodes %+v to any states", zips)
}
return ntg.SearchStates(states)
} }
func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) { func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) {