integration with parcoursmob
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 2m23s
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 2m23s
This commit is contained in:
@@ -46,7 +46,6 @@ func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error) {
|
||||
}
|
||||
|
||||
err = client.Connect(context.TODO())
|
||||
|
||||
if err != nil {
|
||||
return MongoDBStorage{}, err
|
||||
}
|
||||
@@ -68,7 +67,6 @@ func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error) {
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) CreateRegularRoutes(routes []*geojson.FeatureCollection) error {
|
||||
|
||||
log.Debug().Msg("Storage - CreateRegularRoutes")
|
||||
|
||||
documents := []any{}
|
||||
@@ -180,6 +178,15 @@ func (s MongoDBStorage) GetDriverRegularRoutesForTile(day string, gridId int64)
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) DeleteRegularRoutes(ids []string) error {
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["regular_routes"])
|
||||
_, err := collection.DeleteMany(context.Background(), bson.M{"_id": bson.M{"$in": ids}})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error deleteing regular routes")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) GetPassengerRegularRoutesForTile(day string, gridId int64) ([]*geojson.FeatureCollection, error) {
|
||||
findOptions := options.Find()
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["regular_routes"])
|
||||
@@ -224,7 +231,6 @@ func (s MongoDBStorage) GetPassengerRegularRoutesForTile(day string, gridId int6
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) CreateBooking(booking internal.Booking) error {
|
||||
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["bookings"])
|
||||
_, err := collection.InsertOne(context.TODO(), booking)
|
||||
if err != nil {
|
||||
@@ -232,6 +238,7 @@ func (s MongoDBStorage) CreateBooking(booking internal.Booking) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) GetBooking(id string) (booking *internal.Booking, err error) {
|
||||
var b internal.Booking
|
||||
log.Debug().Str("booking id", id).Msg("get booking in DB")
|
||||
@@ -274,7 +281,7 @@ func (s MongoDBStorage) GetUserBookings(userid string) ([]internal.Booking, erro
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) UpdateBookingStatus(bookingid string, status string) error {
|
||||
//TODO implement UpdateBookingStatus
|
||||
// TODO implement UpdateBookingStatus
|
||||
return errors.New("MongoDB Storage - UpdateBookingStatus not implemented")
|
||||
}
|
||||
|
||||
@@ -286,6 +293,7 @@ func (s MongoDBStorage) PersistedKVPut(documents []any) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) PersistedKVGet(id string, document any) error {
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["persisted_kv"])
|
||||
err := collection.FindOne(context.TODO(), bson.M{"_id": id}).Decode(document)
|
||||
@@ -296,7 +304,6 @@ func (s MongoDBStorage) PersistedKVGet(id string, document any) error {
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) StoreRouteSchedules(js []internal.PlannedRouteSchedule) error {
|
||||
|
||||
log.Debug().Msg("Storage - StoreRouteSchedules")
|
||||
|
||||
documents := []any{}
|
||||
@@ -308,7 +315,6 @@ func (s MongoDBStorage) StoreRouteSchedules(js []internal.PlannedRouteSchedule)
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) GetRouteSchedule(id string) (*internal.PlannedRouteSchedule, error) {
|
||||
|
||||
var result internal.PlannedRouteSchedule
|
||||
err := s.PersistedKVGet(id, &result)
|
||||
if err != nil {
|
||||
|
||||
@@ -68,7 +68,6 @@ func NewPostgresqlStorage(cfg *viper.Viper) (PostgresqlStorage, error) {
|
||||
}
|
||||
|
||||
func (s PostgresqlStorage) CreateRegularRoutes(routes []*geojson.FeatureCollection) error {
|
||||
|
||||
log.Debug().Msg("Postgresql Storage - CreateRegularRoutes")
|
||||
|
||||
tx, err := s.DbConnection.Begin()
|
||||
@@ -175,6 +174,15 @@ func (s PostgresqlStorage) GetUserRegularRoutes(userid string) ([]*geojson.Featu
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (s PostgresqlStorage) DeleteRegularRoutes(ids []string) error {
|
||||
req := fmt.Sprintf(`delete from %s where id in $1`, s.Tables["regular_routes"])
|
||||
_, err := s.DbConnection.Exec(req, ids)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error in postgresql request - delete regular routes")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s PostgresqlStorage) GetDriverRegularRoutesForTile(day string, gridId int64) (regular_routes []*geojson.FeatureCollection, err error) {
|
||||
req := fmt.Sprintf(`select id, route
|
||||
from %s inner join %s on id = route_id
|
||||
@@ -434,8 +442,8 @@ func (s PostgresqlStorage) StoreRouteSchedules(journeys []internal.PlannedRouteS
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s PostgresqlStorage) GetRouteSchedule(id string) (*internal.PlannedRouteSchedule, error) {
|
||||
req := fmt.Sprintf("select data from %s where id = $1", s.Tables["journeys_cache"])
|
||||
var jsonjourney []byte
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
type Storage interface {
|
||||
CreateRegularRoutes([]*geojson.FeatureCollection) error
|
||||
GetUserRegularRoutes(userid string) ([]*geojson.FeatureCollection, error)
|
||||
DeleteRegularRoutes(ids []string) error
|
||||
GetDriverRegularRoutesForTile(day string, gridId int64) ([]*geojson.FeatureCollection, error)
|
||||
GetPassengerRegularRoutesForTile(day string, gridId int64) ([]*geojson.FeatureCollection, error)
|
||||
|
||||
@@ -29,9 +30,7 @@ type Storage interface {
|
||||
}
|
||||
|
||||
func NewStorage(cfg *viper.Viper) (Storage, error) {
|
||||
var (
|
||||
storage_type = cfg.GetString("storage.db.type")
|
||||
)
|
||||
storage_type := cfg.GetString("storage.db.type")
|
||||
|
||||
switch storage_type {
|
||||
case "mongodb":
|
||||
|
||||
Reference in New Issue
Block a user