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

@@ -1,3 +1,4 @@
// package internal povides structs used internally within this carpool service
package internal
import (
@@ -11,20 +12,11 @@ import (
"github.com/rs/zerolog/log"
)
type PlannedRouteSchedule struct {
ID string `bson:"_id"`
Route RegularRoute
DepartureDate time.Time
}
// RegularRoute is a utility struct to manipulate regular routes. It's just a GeoJSON feature collection with additional functions
type RegularRoute geojson.FeatureCollection
func (rr RegularRoute) PlannedJourneySchedules(mindate time.Time, maxdate time.Time) ([]PlannedRouteSchedule, error) {
log.Debug().
Str("regular_route.id", rr.ExtraMembers.MustString("id", "")).
Str("mindate", mindate.Format(time.RFC3339)).
Str("maxdate", maxdate.Format(time.RFC3339)).
Msg("carpool service handler - PlannedJourneySchedules")
// PlannedRouteSchedules returns individual planned route schedules with 2 dates, from a regular schedule
func (rr RegularRoute) PlannedRouteSchedules(mindate time.Time, maxdate time.Time) ([]PlannedRouteSchedule, error) {
results := []PlannedRouteSchedule{}
@@ -44,11 +36,13 @@ func (rr RegularRoute) PlannedJourneySchedules(mindate time.Time, maxdate time.T
h, _ := strconv.Atoi(splitted[0])
m, _ := strconv.Atoi(splitted[1])
t := time.Date(current_date.Year(), current_date.Month(), current_date.Day(), h, m, 0, 0, time.Local)
results = append(results, PlannedRouteSchedule{
ID: uuid.NewString(),
Route: rr,
DepartureDate: t,
})
if t.After(time.Now().Add(-1 * time.Hour)) {
results = append(results, PlannedRouteSchedule{
ID: uuid.NewString(),
Route: rr.FeatureCollection(),
DepartureDate: t,
})
}
}
current_date = current_date.Add(24 * time.Hour)
}