aboutsummaryrefslogtreecommitdiff
path: root/pkg/navitia_api_client
diff options
context:
space:
mode:
authorJulien Dessaux2021-09-07 17:32:47 +0200
committerJulien Dessaux2021-09-07 17:32:47 +0200
commitcf7f851a5f47bab8a979135c834dae9ead63a042 (patch)
treedc88a7650ae4ae769afcd3ac35d3b10680a08d84 /pkg/navitia_api_client
parentAdded navitia code to fetch train stops names (diff)
downloadtrains-cf7f851a5f47bab8a979135c834dae9ead63a042.tar.gz
trains-cf7f851a5f47bab8a979135c834dae9ead63a042.tar.bz2
trains-cf7f851a5f47bab8a979135c834dae9ead63a042.zip
Added logic to fetch train stops data if missing when starting the webserver
Diffstat (limited to '')
-rw-r--r--pkg/navitia_api_client/train_stops.go8
-rw-r--r--pkg/navitia_api_client/train_stops_test.go6
2 files changed, 8 insertions, 6 deletions
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