40 lines
871 B
Go
40 lines
871 B
Go
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)
|
|
UpdateVehicle(Vehicle) error
|
|
|
|
//Bookings management
|
|
CreateBooking(Booking) error
|
|
UpdateBooking(Booking) error
|
|
GetBooking(id string) (*Booking, error)
|
|
GetBookings() ([]Booking, error)
|
|
GetBookingsForVehicle(vehicleid string) ([]Booking, error)
|
|
GetBookingsForDriver(driver string) ([]Booking, error)
|
|
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
|
|
default:
|
|
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
|
|
}
|
|
|
|
}
|