2022-08-12 12:49:16 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Storage interface {
|
|
|
|
//Vehicles management
|
|
|
|
CreateVehicle(Vehicle) error
|
|
|
|
GetVehicle(id string) (*Vehicle, error)
|
|
|
|
GetVehicles(namespaces []string) ([]Vehicle, error)
|
2023-05-19 09:26:36 +00:00
|
|
|
UpdateVehicle(Vehicle) error
|
2022-08-12 12:49:16 +00:00
|
|
|
|
|
|
|
//Bookings management
|
|
|
|
CreateBooking(Booking) error
|
2022-09-05 05:26:43 +00:00
|
|
|
UpdateBooking(Booking) error
|
2022-08-12 12:49:16 +00:00
|
|
|
GetBooking(id string) (*Booking, error)
|
2022-09-05 05:26:43 +00:00
|
|
|
GetBookings() ([]Booking, error)
|
2022-08-12 12:49:16 +00:00
|
|
|
GetBookingsForVehicle(vehicleid string) ([]Booking, error)
|
2022-09-05 05:26:43 +00:00
|
|
|
GetBookingsForDriver(driver string) ([]Booking, error)
|
2022-08-12 12:49:16 +00:00
|
|
|
DeleteBooking(id string) 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
|
2023-05-12 13:12:55 +00:00
|
|
|
case "psql":
|
|
|
|
s, err := NewPostgresqlStorage(cfg)
|
|
|
|
return s, err
|
2022-08-12 12:49:16 +00:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|