48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/paulmach/orb/geojson"
|
|
"github.com/rs/zerolog/log"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type MultimodalRoutingHandler struct {
|
|
Carpool *CarpoolRoutingHandler
|
|
}
|
|
|
|
func NewMultimodalRoutingHandler(cfg *viper.Viper) (*MultimodalRoutingHandler, error) {
|
|
carpoolHandler, err := NewCarpoolRoutingHandler(cfg.Sub("carpool"))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not initialize carpool handler : %w", err)
|
|
}
|
|
return &MultimodalRoutingHandler{
|
|
Carpool: carpoolHandler,
|
|
}, nil
|
|
}
|
|
|
|
func (h *MultimodalRoutingHandler) Search(departure geojson.Feature, destination geojson.Feature, departureDate time.Time) ([]*geojson.FeatureCollection, error) {
|
|
ch := make(chan *geojson.FeatureCollection)
|
|
journeys := []*geojson.FeatureCollection{}
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
// Carpool
|
|
wg.Add(1)
|
|
go h.Carpool.Search(ch, &wg, departure, destination, departureDate)
|
|
|
|
go func() {
|
|
wg.Wait()
|
|
close(ch)
|
|
}()
|
|
|
|
for journey := range ch {
|
|
log.Debug().Any("journey", journey).Msg("Received from channel")
|
|
journeys = append(journeys, journey)
|
|
}
|
|
return journeys, nil
|
|
}
|