Add proxied autocomplete for Stadia
This allows me to make the format consistent and to cache the intermediate results, which is useful for speed and testing
This commit is contained in:
parent
b6cfbee102
commit
2d5dca3fb5
11 changed files with 275 additions and 11 deletions
38
platform/geocode/autocomplete.go
Normal file
38
platform/geocode/autocomplete.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package geocode
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/stadia"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type AutocompleteResult struct {
|
||||
Detail string
|
||||
Locality string
|
||||
}
|
||||
|
||||
func Autocomplete(ctx context.Context, org *models.Organization, address string) ([]*AutocompleteResult, error) {
|
||||
req := stadia.RequestGeocodeAutocomplete{
|
||||
Text: address,
|
||||
}
|
||||
maybeAddServiceArea(&req, org)
|
||||
resp, err := client.GeocodeAutocomplete(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("client raw geocode failure on %s: %w", address, err)
|
||||
}
|
||||
result := make([]*AutocompleteResult, len(resp.Features))
|
||||
for i, r := range resp.Features {
|
||||
if r.Type != "Feature" {
|
||||
log.Error().Str("type", r.Type).Msg("should be handled from Stadia")
|
||||
continue
|
||||
}
|
||||
result[i] = &AutocompleteResult{
|
||||
Detail: r.Properties.Name,
|
||||
Locality: r.Properties.Locality,
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
|
@ -267,6 +267,9 @@ func allFeaturesIdenticalEnough(features []stadia.GeocodeFeature) bool {
|
|||
return true
|
||||
}
|
||||
func maybeAddServiceArea(req stadia.RequestGeocode, org *models.Organization) {
|
||||
if org == nil {
|
||||
return
|
||||
}
|
||||
if org.ServiceAreaXmax.IsNull() ||
|
||||
org.ServiceAreaYmax.IsNull() ||
|
||||
org.ServiceAreaXmin.IsNull() ||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue