Properly handle REFERENCE_ID for future changes
This commit is contained in:
@@ -1,59 +1,66 @@
|
||||
package bus
|
||||
|
||||
import (
|
||||
"strings"
|
||||
query "github.com/tgckpg/golifehk/query"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
query "github.com/tgckpg/golifehk/query"
|
||||
)
|
||||
|
||||
func Query( lang string, message string ) query.IQueryResult {
|
||||
func Query(lang string, message string) query.IQueryResult {
|
||||
|
||||
var qBusStops *query.QueryObject
|
||||
var err error
|
||||
var qBusStops *query.QueryObject
|
||||
var err error
|
||||
|
||||
qr := QueryResult{ Lang: lang }
|
||||
busStops, err := getBusStops()
|
||||
if err != nil {
|
||||
qr.Error = err
|
||||
goto qrReturn
|
||||
}
|
||||
qr := QueryResult{Lang: lang}
|
||||
busStops, err := getBusStops()
|
||||
if err != nil {
|
||||
qr.Error = err
|
||||
goto qrReturn
|
||||
}
|
||||
|
||||
qBusStops, err = query.Parse( strings.ToUpper( message ), busStops )
|
||||
if err != nil {
|
||||
qr.Error = err
|
||||
goto qrReturn
|
||||
}
|
||||
qBusStops, err = query.Parse(strings.ToUpper(message), busStops)
|
||||
if err != nil {
|
||||
qr.Error = err
|
||||
goto qrReturn
|
||||
}
|
||||
|
||||
qr.Query = qBusStops
|
||||
if 0 < len( *qBusStops.Results ) && 1 < len( *qBusStops.SearchTerms ) {
|
||||
schedules, err := getSchedule( lang, qBusStops.Key )
|
||||
if err != nil {
|
||||
qr.Error = err
|
||||
goto qrReturn
|
||||
}
|
||||
qr.Query = qBusStops
|
||||
if 0 < len(*qBusStops.Results) && 1 < len(*qBusStops.SearchTerms) {
|
||||
schedules, err := getSchedule(lang, qBusStops.Key)
|
||||
if err != nil {
|
||||
qr.Error = err
|
||||
goto qrReturn
|
||||
}
|
||||
|
||||
if len( schedules.BusStops ) == 0 {
|
||||
qr.Schedules = &map[*BusStop] *BusStopBuses{}
|
||||
goto qrReturn
|
||||
}
|
||||
if len(schedules.BusStops) == 0 {
|
||||
qr.Schedules = &map[*BusStop]*BusStopBuses{}
|
||||
goto qrReturn
|
||||
}
|
||||
|
||||
matches := map[*BusStop] *BusStopBuses{}
|
||||
for _, entry := range *qBusStops.Results {
|
||||
busStop := any( entry ).( *BusStop )
|
||||
matches := map[*BusStop]*BusStopBuses{}
|
||||
for _, entry := range *qBusStops.Results {
|
||||
busStop := any(entry).(*BusStop)
|
||||
|
||||
for _, busStopSch := range schedules.BusStops {
|
||||
if busStopSch.BusStopId == busStop.StationId {
|
||||
matches[busStop] = &busStopSch
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, busStopSch := range schedules.BusStops {
|
||||
if busStopSch.BusStopId == busStop.StationId {
|
||||
if busStop.RouteId != busStop.ReferenceId {
|
||||
// There were no indicator for special routes from getSchedule API
|
||||
log.Printf("Ignoring special route matches: %s", busStop.ReferenceId)
|
||||
continue
|
||||
}
|
||||
matches[busStop] = &busStopSch
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
qr.Schedules = &matches
|
||||
}
|
||||
qr.Schedules = &matches
|
||||
}
|
||||
|
||||
qrReturn:
|
||||
var iqr query.IQueryResult
|
||||
iqr = &qr
|
||||
return iqr
|
||||
qrReturn:
|
||||
var iqr query.IQueryResult
|
||||
iqr = &qr
|
||||
return iqr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user