Compare commits
No commits in common. "286d1af9085338b5acbcce1b66f7173d94561018" and "ea52c6132f159618b200685f6d4379ded032389f" have entirely different histories.
286d1af908
...
ea52c6132f
@ -118,7 +118,7 @@ func convertCode(t, code string) string {
|
|||||||
|
|
||||||
func searchLine(t, code string) string {
|
func searchLine(t, code string) string {
|
||||||
for _, line := range IDFMLines {
|
for _, line := range IDFMLines {
|
||||||
if line.Fields.ShortName == code && (line.Fields.TransportMode == t || strings.ToLower(line.Fields.NetworkName) == t) {
|
if line.Fields.ShortName == code && (line.Fields.TransportMode == t || line.Fields.NetworkName == t) {
|
||||||
return line.Fields.IdLine
|
return line.Fields.IdLine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@ package api
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
@ -36,7 +34,6 @@ type IDFMRealTimeData struct {
|
|||||||
type IDFMRealTime struct {
|
type IDFMRealTime struct {
|
||||||
NextDepartures struct {
|
NextDepartures struct {
|
||||||
StatusCode int `json:"statusCode"`
|
StatusCode int `json:"statusCode"`
|
||||||
ErrorMessage string `json:"errorMessage"`
|
|
||||||
Data []IDFMRealTimeData `json:"data"`
|
Data []IDFMRealTimeData `json:"data"`
|
||||||
} `json:"nextDepartures"`
|
} `json:"nextDepartures"`
|
||||||
CrowdsourcingReports struct {
|
CrowdsourcingReports struct {
|
||||||
@ -117,8 +114,6 @@ func getRealTime(code, station string) (*IDFMRealTime, error) {
|
|||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
if res.StatusCode >= 400 {
|
if res.StatusCode >= 400 {
|
||||||
v, _ := io.ReadAll(res.Body)
|
|
||||||
log.Println("Schedule not found: ", string(v))
|
|
||||||
return nil, fmt.Errorf("Schedule not found")
|
return nil, fmt.Errorf("Schedule not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,18 +124,13 @@ func getRealTime(code, station string) (*IDFMRealTime, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if schedules.NextDepartures.StatusCode >= 400 {
|
|
||||||
log.Println("Schedule not found: ", schedules)
|
|
||||||
return nil, fmt.Errorf("Schedule not found: %s", schedules.NextDepartures.ErrorMessage)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &schedules, nil
|
return &schedules, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func declareSchedulesRoutes(router *gin.RouterGroup) {
|
func declareSchedulesRoutes(router *gin.RouterGroup) {
|
||||||
router.GET("/schedules/:type/:code/:station/:way", func(c *gin.Context) {
|
router.GET("/schedules/:type/:code/:station/:way", func(c *gin.Context) {
|
||||||
t := convertLineType(string(c.Param("type")))
|
t := convertLineType(string(c.Param("type")))
|
||||||
code := convertCode(t, string(c.Param("code")))
|
code := string(c.Param("code"))
|
||||||
station := string(c.Param("station"))
|
station := string(c.Param("station"))
|
||||||
way := string(c.Param("way"))
|
way := string(c.Param("way"))
|
||||||
|
|
||||||
@ -164,7 +154,6 @@ func declareSchedulesRoutes(router *gin.RouterGroup) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("search", code, station)
|
|
||||||
schedules, err := getRealTime(code, station)
|
schedules, err := getRealTime(code, station)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user