golifehk/datasources/kmb/query.go

50 lines
1.0 KiB
Go
Raw Permalink Normal View History

2022-09-16 20:33:47 +00:00
package kmb
import (
"strings"
query "github.com/tgckpg/golifehk/query"
)
func Query( lang string, message string ) query.IQueryResult {
var qo *query.QueryObject
var err error
qr := QueryResult{ Lang: lang }
2022-09-25 10:48:22 +00:00
routeStops, err := getRouteStops()
2022-09-16 20:33:47 +00:00
if err != nil {
qr.Error = err
goto qrReturn
}
2022-09-25 10:48:22 +00:00
qo, err = query.Parse( strings.ToUpper( message ), routeStops )
2022-09-16 20:33:47 +00:00
if err != nil {
qr.Error = err
goto qrReturn
}
qr.Query = qo
2022-09-25 10:48:22 +00:00
if 0 < len( *qo.Results ) && 1 < len( *qo.SearchTerms ) {
rSchedules := map[*RouteStop] *[] *Schedule{}
for _, item := range *qo.Results {
var r *RouteStop
r = any( item ).( *RouteStop )
schedules, err := getSchedule( r )
if err != nil {
qr.Error = err
break
}
rSchedules[r] = schedules
}
qr.Schedules = &rSchedules
}
2022-09-16 20:33:47 +00:00
qrReturn:
var iqr query.IQueryResult
iqr = &qr
return iqr
}