Add PostgreSQL database option and more booking flow functionalities

This commit is contained in:
2023-05-08 01:29:59 +02:00
parent d8346a20be
commit e2e6759dc0
40 changed files with 1594 additions and 907 deletions

View File

@@ -10,7 +10,8 @@ import (
"github.com/rs/zerolog/log"
)
func (h *CarpoolServiceHandler) GetDriverJourneys(departure orb.Point, arrival orb.Point, departureRadius *float64, arrivalRadius *float64, minDate time.Time, maxDate time.Time, count *int64) ([]internal.SearchResult, error) {
// GetDriverJourneys searches for matching punctual planned driver journeys.
func (h *CarpoolServiceHandler) GetDriverJourneys(departure orb.Point, arrival orb.Point, departureRadius *float64, arrivalRadius *float64, minDate time.Time, maxDate time.Time, count *int64) ([]internal.PlannedRouteSchedule, error) {
log.Debug().
Any("departure", departure).
@@ -51,14 +52,12 @@ func (h *CarpoolServiceHandler) GetDriverJourneys(departure orb.Point, arrival o
candidate_routes := tileset.GetTiledRoutes()
journeys := []internal.SearchResult{}
journeys := []internal.PlannedRouteSchedule{}
counted := int64(0)
for _, r := range candidate_routes {
ls := r.Route.Features[2].Geometry.(orb.LineString)
// distanceFromDeparture, indexDeparture := planar.DistanceFromWithIndex(ls, departure)
// distanceFromArrival, indexArrival := planar.DistanceFromWithIndex(ls, arrival)
distanceFromDeparture, indexDeparture := geoutils.DistanceFromLineString(departure, ls)
distanceFromArrival, indexArrival := geoutils.DistanceFromLineString(arrival, ls)
@@ -71,7 +70,7 @@ func (h *CarpoolServiceHandler) GetDriverJourneys(departure orb.Point, arrival o
log.Error().Err(err).Msg("error getting route with viapoints")
continue
}
journeys = append(journeys, internal.SearchResult{
journeys = append(journeys, internal.PlannedRouteSchedule{
ID: r.ID,
Route: r.Route,
DepartureDate: r.DepartureDate,
@@ -85,7 +84,7 @@ func (h *CarpoolServiceHandler) GetDriverJourneys(departure orb.Point, arrival o
}
if len(journeys) > 0 {
err = h.Storage.StoreSearchResults(journeys)
err = h.Storage.StoreRouteSchedules(journeys)
if err != nil {
log.Error().Err(err).Msg("Error saving search results")
return nil, err
@@ -95,7 +94,8 @@ func (h *CarpoolServiceHandler) GetDriverJourneys(departure orb.Point, arrival o
return journeys, nil
}
func (h *CarpoolServiceHandler) GetPassengerJourneys(departure orb.Point, arrival orb.Point, departureRadius *float64, arrivalRadius *float64, minDate time.Time, maxDate time.Time, count *int64) ([]internal.SearchResult, error) {
// GetPassengerJourneys searches for matching punctual planned passenger journeys.
func (h *CarpoolServiceHandler) GetPassengerJourneys(departure orb.Point, arrival orb.Point, departureRadius *float64, arrivalRadius *float64, minDate time.Time, maxDate time.Time, count *int64) ([]internal.PlannedRouteSchedule, error) {
log.Debug().
Any("departure", departure).
@@ -151,7 +151,7 @@ func (h *CarpoolServiceHandler) GetPassengerJourneys(departure orb.Point, arriva
candidate_routes := tileset.GetTiledRoutes()
journeys := []internal.SearchResult{}
journeys := []internal.PlannedRouteSchedule{}
counted := int64(0)
for _, r := range candidate_routes {
@@ -167,7 +167,7 @@ func (h *CarpoolServiceHandler) GetPassengerJourneys(departure orb.Point, arriva
log.Error().Err(err).Msg("error getting route with viapoints")
continue
}
journeys = append(journeys, internal.SearchResult{
journeys = append(journeys, internal.PlannedRouteSchedule{
ID: r.ID,
Route: r.Route,
DepartureDate: r.DepartureDate,
@@ -181,7 +181,7 @@ func (h *CarpoolServiceHandler) GetPassengerJourneys(departure orb.Point, arriva
}
if len(journeys) > 0 {
err = h.Storage.StoreSearchResults(journeys)
err = h.Storage.StoreRouteSchedules(journeys)
if err != nil {
log.Error().Err(err).Msg("Error saving search results")
return nil, err