From d2cf8c74a2c85e4774d70d80d3fd191ea8915729 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Thu, 27 Jan 2022 18:14:49 -0700 Subject: [PATCH] ntgvision maps zips to states then does same query --- broker/ntgvision.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/broker/ntgvision.go b/broker/ntgvision.go index f95f365..4c3e5fd 100644 --- a/broker/ntgvision.go +++ b/broker/ntgvision.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "local/truckstop/config" "local/truckstop/logtr" + "local/truckstop/zip" "net/http" "time" ) @@ -188,7 +189,22 @@ func (ntg NTGVision) searchJob(id int64) (ntgVisionJobInfo, 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) {