Refactoring codes for more tg message types
This commit is contained in:
@@ -1,65 +1,66 @@
|
||||
package kmb
|
||||
|
||||
import (
|
||||
query "github.com/tgckpg/golifehk/query"
|
||||
query "github.com/tgckpg/golifehk/query"
|
||||
)
|
||||
|
||||
type RouteStop struct {
|
||||
BusStop *BusStop
|
||||
RouteId string `json:"route"`
|
||||
ServiceType string `json:"service_type"`
|
||||
Direction string `json:"bound"`
|
||||
StationSeq int `json:"seq,string"`
|
||||
StationId string `json:"stop"`
|
||||
BusStop *BusStop
|
||||
RouteId string `json:"route"`
|
||||
ServiceType string `json:"service_type"`
|
||||
Direction string `json:"bound"`
|
||||
StationSeq int `json:"seq,string"`
|
||||
StationId string `json:"stop"`
|
||||
|
||||
RouteStops *map[int] *RouteStop
|
||||
query.Searchable
|
||||
RouteStops *map[int]*RouteStop
|
||||
query.Words
|
||||
query.NoGeoLocation
|
||||
}
|
||||
|
||||
type RouteStops struct {
|
||||
Type string `json:"type"`
|
||||
Version string `json:"version"`
|
||||
DateCreated string `json:"generated_timestamp"`
|
||||
RouteStops [] *RouteStop `json:"data"`
|
||||
Type string `json:"type"`
|
||||
Version string `json:"version"`
|
||||
DateCreated string `json:"generated_timestamp"`
|
||||
RouteStops []*RouteStop `json:"data"`
|
||||
}
|
||||
|
||||
func ( routeStop RouteStop ) PrevStop() *RouteStop {
|
||||
if v, hasKey := (*routeStop.RouteStops)[ routeStop.StationSeq - 1 ]; hasKey {
|
||||
return v
|
||||
}
|
||||
return nil
|
||||
func (routeStop RouteStop) PrevStop() *RouteStop {
|
||||
if v, hasKey := (*routeStop.RouteStops)[routeStop.StationSeq-1]; hasKey {
|
||||
return v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ( routeStop RouteStop ) NextStop() *RouteStop {
|
||||
if v, hasKey := (*routeStop.RouteStops)[ routeStop.StationSeq + 1 ]; hasKey {
|
||||
return v
|
||||
}
|
||||
return nil
|
||||
func (routeStop RouteStop) NextStop() *RouteStop {
|
||||
if v, hasKey := (*routeStop.RouteStops)[routeStop.StationSeq+1]; hasKey {
|
||||
return v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ( this *RouteStop ) Reload() {
|
||||
func (this *RouteStop) Reload() {
|
||||
|
||||
searchData := [] *string{}
|
||||
busStop := *this.BusStop
|
||||
searchData = append( searchData, &busStop.Name_en )
|
||||
searchData = append( searchData, &busStop.Name_tc )
|
||||
searchData := []*string{}
|
||||
busStop := *this.BusStop
|
||||
searchData = append(searchData, &busStop.Name_en)
|
||||
searchData = append(searchData, &busStop.Name_tc)
|
||||
|
||||
this.Key = &this.RouteId
|
||||
this.SearchData = &searchData
|
||||
this.Key = &this.RouteId
|
||||
this.SearchData = &searchData
|
||||
}
|
||||
|
||||
type ByRoute [] *RouteStop
|
||||
type ByRoute []*RouteStop
|
||||
|
||||
func (a ByRoute) Len() int { return len(a) }
|
||||
func (a ByRoute) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByRoute) Len() int { return len(a) }
|
||||
func (a ByRoute) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByRoute) Less(i, j int) bool {
|
||||
_a := *a[i]
|
||||
_b := *a[j]
|
||||
if _a.RouteId == _b.RouteId {
|
||||
if _a.Direction == _b.Direction {
|
||||
return _a.ServiceType < _b.ServiceType
|
||||
}
|
||||
return _a.Direction < _b.Direction
|
||||
}
|
||||
return _a.RouteId < _b.RouteId
|
||||
_a := *a[i]
|
||||
_b := *a[j]
|
||||
if _a.RouteId == _b.RouteId {
|
||||
if _a.Direction == _b.Direction {
|
||||
return _a.ServiceType < _b.ServiceType
|
||||
}
|
||||
return _a.Direction < _b.Direction
|
||||
}
|
||||
return _a.RouteId < _b.RouteId
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user