Refactor
This commit is contained in:
parent
da0187b74d
commit
5a5f81c0fb
@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -107,26 +106,13 @@ func getSchedules(code string) (*IDFMSchedule, error) {
|
||||
return &schedules, nil
|
||||
}
|
||||
|
||||
func declareDestinationsRoutes(router *gin.RouterGroup) {
|
||||
router.GET("/destinations/:type/:code", func(c *gin.Context) {
|
||||
t := convertLineType(string(c.Param("type")))
|
||||
code := string(c.Param("code"))
|
||||
|
||||
if !strings.HasPrefix(code, "line:IDFM:") {
|
||||
if len(code) != 6 || !strings.HasPrefix(code, "C") {
|
||||
code = searchLine(t, code)
|
||||
}
|
||||
|
||||
code = "line:IDFM:" + code
|
||||
}
|
||||
|
||||
func getDestinations(code string) ([]PGDestination, error) {
|
||||
schedule, err := getSchedules(code)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pgd := []PGDestination{}
|
||||
var pgd []PGDestination
|
||||
|
||||
destination:
|
||||
for i, s := range schedule.Schedules {
|
||||
@ -147,6 +133,20 @@ func declareDestinationsRoutes(router *gin.RouterGroup) {
|
||||
})
|
||||
}
|
||||
|
||||
return pgd, nil
|
||||
}
|
||||
|
||||
func declareDestinationsRoutes(router *gin.RouterGroup) {
|
||||
router.GET("/destinations/:type/:code", func(c *gin.Context) {
|
||||
t := convertLineType(string(c.Param("type")))
|
||||
code := convertCode(t, string(c.Param("code")))
|
||||
|
||||
pgd, err := getDestinations(code)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, APIResult(c, map[string][]PGDestination{
|
||||
"destinations": pgd,
|
||||
}))
|
||||
|
@ -164,7 +164,7 @@ func declareSchedulesRoutes(router *gin.RouterGroup) {
|
||||
|
||||
pgs := []PGSchedule{}
|
||||
for _, vehicule := range schedules.NextDepartures.Data {
|
||||
if (way == "A" && vehicule.Sens == "-1") || (way == "R" && vehicule.Sens == "1") {
|
||||
if (way == "A" && vehicule.Sens == "1") || (way == "R" && vehicule.Sens == "-1") {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -106,15 +106,7 @@ func getStations(code string) (stations []IDFMStation, err error) {
|
||||
func declareStationsRoutes(router *gin.RouterGroup) {
|
||||
router.GET("/stations/:type/:code", func(c *gin.Context) {
|
||||
t := convertLineType(string(c.Param("type")))
|
||||
code := string(c.Param("code"))
|
||||
|
||||
if !strings.HasPrefix(code, "line:IDFM:") {
|
||||
if len(code) != 6 || !strings.HasPrefix(code, "C") {
|
||||
code = searchLine(t, code)
|
||||
}
|
||||
|
||||
code = "line:IDFM:" + code
|
||||
}
|
||||
code := convertCode(t, string(c.Param("code")))
|
||||
|
||||
stations, err := getStations(code)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user