Get all bookings
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 44s
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 44s
This commit is contained in:
@@ -412,6 +412,66 @@ func (s PostgresqlStorage) GetUserBookings(userid string) ([]internal.Booking, e
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (s PostgresqlStorage) GetAllBookings() ([]internal.Booking, error) {
|
||||
req := fmt.Sprintf(`select booking, status, driver_route, passenger_route from %s
|
||||
where 1=1`, s.Tables["bookings"])
|
||||
rows, err := s.DbConnection.Query(req)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("GetUserBookings query issue")
|
||||
}
|
||||
|
||||
results := []internal.Booking{}
|
||||
for rows.Next() {
|
||||
var booking ocss.Booking
|
||||
var status string
|
||||
var bookingbytes, driverroute, passengerroute []byte
|
||||
err := rows.Scan(
|
||||
&bookingbytes,
|
||||
&status,
|
||||
&driverroute,
|
||||
&passengerroute,
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("not able to get and scan booking in GetUsersBooking")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(bookingbytes, &booking)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("issue unmarshalling booking in GetUsersBooking")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Override booking status
|
||||
booking.Status = ocss.BookingStatusFromString(status)
|
||||
|
||||
var dr, pr *geojson.FeatureCollection
|
||||
if driverroute != nil {
|
||||
dr, err = geojson.UnmarshalFeatureCollection(driverroute)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not unmarshal driver route feature collection")
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if passengerroute != nil {
|
||||
pr, err = geojson.UnmarshalFeatureCollection(passengerroute)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not unmarshal passenger route feature collection")
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
results = append(results, internal.Booking{
|
||||
Booking: booking,
|
||||
DriverRoute: dr,
|
||||
PassengerRoute: pr,
|
||||
})
|
||||
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (s PostgresqlStorage) StoreRouteSchedules(journeys []internal.PlannedRouteSchedule) error {
|
||||
tx, err := s.DbConnection.Begin()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user