47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package storage
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.coopgo.io/coopgo-platform/carpool-service/internal"
|
|
"github.com/paulmach/orb/geojson"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type Storage interface {
|
|
CreateRegularRoutes([]*geojson.FeatureCollection) error
|
|
GetUserRegularRoutes(userid string) ([]*geojson.FeatureCollection, error)
|
|
GetDriverRegularRoutesForTile(day string, gridId int64) ([]*geojson.FeatureCollection, error)
|
|
GetPassengerRegularRoutesForTile(day string, gridId int64) ([]*geojson.FeatureCollection, error)
|
|
|
|
CreateBooking(internal.Booking) error
|
|
GetBooking(id string) (*internal.Booking, error)
|
|
GetUserBookings(userid string) ([]internal.Booking, error)
|
|
UpdateBookingStatus(bookingid string, status string) error
|
|
|
|
// Caching temporary results
|
|
// PersistedKVPut(documents []any) error
|
|
// PersistedKVGet(id string, document any) error
|
|
StoreRouteSchedules([]internal.PlannedRouteSchedule) error
|
|
GetRouteSchedule(id string) (*internal.PlannedRouteSchedule, error)
|
|
|
|
Migrate() error
|
|
}
|
|
|
|
func NewStorage(cfg *viper.Viper) (Storage, error) {
|
|
var (
|
|
storage_type = cfg.GetString("storage.db.type")
|
|
)
|
|
|
|
switch storage_type {
|
|
case "mongodb":
|
|
s, err := NewMongoDBStorage(cfg)
|
|
return s, err
|
|
case "psql":
|
|
s, err := NewPostgresqlStorage(cfg)
|
|
return s, err
|
|
default:
|
|
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
|
|
}
|
|
}
|