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:
@@ -280,6 +280,29 @@ func (s MongoDBStorage) GetUserBookings(userid string) ([]internal.Booking, erro
|
||||
return bookings, nil
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) GetAllBookings() ([]internal.Booking, error) {
|
||||
findOptions := options.Find()
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["bookings"])
|
||||
cur, err := collection.Find(context.TODO(), bson.M{}, findOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var bookings []internal.Booking
|
||||
for cur.Next(context.TODO()) {
|
||||
var elem internal.Booking
|
||||
|
||||
if err := cur.Decode(&elem); err != nil {
|
||||
log.Error().Err(err).Msg("error reading bookings response")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bookings = append(bookings, elem)
|
||||
}
|
||||
|
||||
return bookings, nil
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) UpdateBookingStatus(bookingid string, status string) error {
|
||||
// TODO implement UpdateBookingStatus
|
||||
return errors.New("MongoDB Storage - UpdateBookingStatus not implemented")
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -18,6 +18,7 @@ type Storage interface {
|
||||
CreateBooking(internal.Booking) error
|
||||
GetBooking(id string) (*internal.Booking, error)
|
||||
GetUserBookings(userid string) ([]internal.Booking, error)
|
||||
GetAllBookings() ([]internal.Booking, error)
|
||||
UpdateBookingStatus(bookingid string, status string) error
|
||||
|
||||
// Caching temporary results
|
||||
|
||||
Reference in New Issue
Block a user