Sort lines
This commit is contained in:
parent
5a5f81c0fb
commit
ee181e43fd
29
api/lines.go
29
api/lines.go
@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -50,6 +51,20 @@ type PGLine struct {
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type ByName []PGLine
|
||||
|
||||
func (s ByName) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func (s ByName) Less(i, j int) bool {
|
||||
return strings.Compare(s[i].Id, s[j].Id) <= 0
|
||||
}
|
||||
|
||||
func (s ByName) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
|
||||
var IDFMLines []IDFMLine
|
||||
|
||||
func init() {
|
||||
@ -82,6 +97,18 @@ func convertLineType(old string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func convertCode(t, code string) string {
|
||||
if !strings.HasPrefix(code, "line:IDFM:") {
|
||||
if len(code) != 6 || !strings.HasPrefix(code, "C") {
|
||||
code = searchLine(t, code)
|
||||
}
|
||||
|
||||
code = "line:IDFM:" + code
|
||||
}
|
||||
|
||||
return code
|
||||
}
|
||||
|
||||
func searchLine(t, code string) string {
|
||||
for _, line := range IDFMLines {
|
||||
if line.Fields.ShortName == code && (line.Fields.TransportMode == t || line.Fields.NetworkName == t) {
|
||||
@ -141,6 +168,8 @@ func declareLinesRoutes(router *gin.RouterGroup) {
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(ByName(lines))
|
||||
|
||||
c.JSON(http.StatusOK, APIResult(c, map[string][]PGLine{
|
||||
string(c.Param("type")): lines,
|
||||
}))
|
||||
|
Loading…
Reference in New Issue
Block a user