From cf7f851a5f47bab8a979135c834dae9ead63a042 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 7 Sep 2021 17:32:47 +0200 Subject: Added logic to fetch train stops data if missing when starting the webserver --- pkg/navitia_api_client/train_stops.go | 8 ++++---- pkg/navitia_api_client/train_stops_test.go | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'pkg/navitia_api_client') diff --git a/pkg/navitia_api_client/train_stops.go b/pkg/navitia_api_client/train_stops.go index c8a8ff2..a31ccf7 100644 --- a/pkg/navitia_api_client/train_stops.go +++ b/pkg/navitia_api_client/train_stops.go @@ -3,7 +3,6 @@ package navitia_api_client import ( "encoding/json" "fmt" - "log" "net/http" "git.adyxax.org/adyxax/trains/pkg/model" @@ -22,7 +21,7 @@ type TrainStopsResponse struct { Codes []interface{} `json:"codes"` Links []interface{} `json:"links"` Coord interface{} `json:"coord"` - Label interface{} `json:"label"` + Label string `json:"label"` Timezone interface{} `json:"timezone"` AdministrativeRegion interface{} `json:"administrative_regions"` } `json:"stop_areas"` @@ -53,10 +52,11 @@ func getTrainStopsPage(c *NavitiaClient, i int) (trainStops []model.TrainStop, e return nil, newJsonDecodeError("GetTrainStops ", err) } for i := 0; i < len(data.StopAreas); i++ { - trainStops = append(trainStops, model.TrainStop{data.StopAreas[i].ID, data.StopAreas[i].Name}) + if data.StopAreas[i].Label != "" { + trainStops = append(trainStops, model.TrainStop{data.StopAreas[i].ID, data.StopAreas[i].Label}) + } } if data.Pagination.ItemsOnPage+data.Pagination.ItemsPerPage*data.Pagination.StartPage < data.Pagination.TotalResult { - log.Printf("pagination %d\n", i) tss, err := getTrainStopsPage(c, i+1) if err != nil { return nil, err diff --git a/pkg/navitia_api_client/train_stops_test.go b/pkg/navitia_api_client/train_stops_test.go index 93fc43f..9e1c982 100644 --- a/pkg/navitia_api_client/train_stops_test.go +++ b/pkg/navitia_api_client/train_stops_test.go @@ -76,7 +76,8 @@ func TestGetTrainStops(t *testing.T) { if err != nil { t.Fatalf("could not get train stops : %s", err) } - if len(trainStops) != 4 { + // 4 records but one is empty (navitia api quirk) + if len(trainStops) != 3 { t.Fatalf("did not decode train stops properly, got %d train stops when expected 4", len(trainStops)) } // normal request in multiple pages @@ -90,7 +91,8 @@ func TestGetTrainStops(t *testing.T) { if err != nil { t.Fatalf("could not get train stops : %+v", err) } - if len(trainStops) != 12 { + // 12 records but one is empty (navitia api quirk) + if len(trainStops) != 11 { t.Fatalf("did not decode train stops properly, got %d train stops when expected 4", len(trainStops)) } // failing request in multiple pages with last one missing -- cgit v1.2.3