solidarity-service/storage/storage.go

36 lines
1.2 KiB
Go
Raw Normal View History

2023-10-20 11:41:39 +00:00
package storage
import (
"fmt"
"github.com/paulmach/orb/geojson"
"github.com/spf13/viper"
"solidarity-service/internal"
)
type Storage interface {
CreatePassenger(passenger internal.Passenger) (err error)
GetPassenger(passengerID string) (passenger internal.Passenger, err error)
2024-09-25 13:16:34 +00:00
GetAllPassengers() (passengers []internal.Passenger, err error)
2023-10-20 11:41:39 +00:00
CreateDriver(driver internal.Driver) (err error)
GetDriver(driverID string) (driver internal.Driver, err error)
GetBooking(id string) (booking internal.Booking, err error)
CreateBooking(booking internal.BookingRequest) (err error)
UpdateBookingStatus(id string, status internal.BookingStatus) (err error)
FilterUserBookingsByStatus(user_type string, status internal.BookingStatus, user_id string) (bookings []internal.Booking, err error)
DriverJourneys(departure_route *geojson.Feature, departure_date int64) (drivers []internal.Driver, err error)
GetAllDrivers(date int64) (drivers []internal.Driver, err error)
}
func NewStorage(cfg *viper.Viper) (Storage, error) {
var (
storage_type = cfg.GetString("storage.db.type")
)
switch storage_type {
case "psql":
s, err := NewPostgresqlStorage(cfg)
return s, err
default:
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
}
}