storage

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusOld         = -1
	StatusOngoing     = 0
	StatusForthcoming = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Booking

type Booking struct {
	ID              string         `json:"id" bson:"_id"`
	Vehicleid       string         `json:"vehicleid"`
	Driver          string         `json:"driver"`
	Startdate       time.Time      `json:"startdate"`
	Enddate         time.Time      `json:"enddate"`
	Unavailablefrom time.Time      `json:"unavailablefrom"`
	Unavailableto   time.Time      `json:"unavailableto"`
	Data            map[string]any `json:"data"`

	Deleted bool    `json:"deleted"`
	Vehicle Vehicle `json:"vehicle" bson:"-"`

	ManualStatus  string               `json:"manual_status" bson:"manual_status"`
	StatusHistory []StatusHistoryEntry `json:"status_history" bson:"status_history"`
}

func (Booking) Status

func (b Booking) Status() int

type MongoDBStorage

type MongoDBStorage struct {
	*mongo.Client
	DbName      string
	Collections map[string]string
}

func NewMongoDBStorage

func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error)

func (MongoDBStorage) CreateBooking

func (s MongoDBStorage) CreateBooking(booking Booking) error

func (MongoDBStorage) CreateVehicle

func (s MongoDBStorage) CreateVehicle(vehicle Vehicle) error

func (MongoDBStorage) DeleteBooking

func (s MongoDBStorage) DeleteBooking(bookingid string) error

func (MongoDBStorage) GetBooking

func (s MongoDBStorage) GetBooking(id string) (*Booking, error)

func (MongoDBStorage) GetBookings

func (s MongoDBStorage) GetBookings() (bookings []Booking, err error)

func (MongoDBStorage) GetBookingsForDriver

func (s MongoDBStorage) GetBookingsForDriver(driver string) (bookings []Booking, err error)

func (MongoDBStorage) GetBookingsForVehicle

func (s MongoDBStorage) GetBookingsForVehicle(vehicleid string) (bookings []Booking, err error)

func (MongoDBStorage) GetVehicle

func (s MongoDBStorage) GetVehicle(id string) (*Vehicle, error)

func (MongoDBStorage) GetVehicles

func (s MongoDBStorage) GetVehicles(namespaces []string) (vehicles []Vehicle, err error)

func (MongoDBStorage) UpdateBooking

func (s MongoDBStorage) UpdateBooking(booking Booking) error

func (MongoDBStorage) UpdateVehicle

func (s MongoDBStorage) UpdateVehicle(vehicle Vehicle) error

///////////////////update///////////////

type PostgresqlStorage

type PostgresqlStorage struct {
	DbConnection *sql.DB
	Schema       string
	Tables       map[string]string
}

func NewPostgresqlStorage

func NewPostgresqlStorage(cfg *viper.Viper) (PostgresqlStorage, error)

func (PostgresqlStorage) CreateBooking

func (psql PostgresqlStorage) CreateBooking(booking Booking) error

func (PostgresqlStorage) CreateVehicle

func (psql PostgresqlStorage) CreateVehicle(vehicle Vehicle) error

func (PostgresqlStorage) DeleteBooking

func (psql PostgresqlStorage) DeleteBooking(id string) error

func (PostgresqlStorage) GetBooking

func (psql PostgresqlStorage) GetBooking(id string) (*Booking, error)

func (PostgresqlStorage) GetBookings

func (psql PostgresqlStorage) GetBookings() ([]Booking, error)

func (PostgresqlStorage) GetBookingsForDriver

func (psql PostgresqlStorage) GetBookingsForDriver(driver string) ([]Booking, error)

func (PostgresqlStorage) GetBookingsForVehicle

func (psql PostgresqlStorage) GetBookingsForVehicle(vehicleid string) ([]Booking, error)

func (PostgresqlStorage) GetVehicle

func (psql PostgresqlStorage) GetVehicle(id string) (*Vehicle, error)

func (PostgresqlStorage) GetVehicles

func (psql PostgresqlStorage) GetVehicles(namespaces []string) ([]Vehicle, error)

func (PostgresqlStorage) Migrate

func (psql PostgresqlStorage) Migrate() error

func (PostgresqlStorage) UpdateBooking

func (psql PostgresqlStorage) UpdateBooking(bookingToUpdate Booking) error

func (PostgresqlStorage) UpdateVehicle

func (psql PostgresqlStorage) UpdateVehicle(vehicle Vehicle) error

type StatusHistoryEntry

type StatusHistoryEntry struct {
	FromStatus string    `json:"from_status" bson:"from_status"`
	ToStatus   string    `json:"to_status" bson:"to_status"`
	UserID     string    `json:"user_id" bson:"user_id"`
	UserName   string    `json:"user_name" bson:"user_name"`
	GroupID    string    `json:"group_id" bson:"group_id"`
	GroupName  string    `json:"group_name" bson:"group_name"`
	Date       time.Time `json:"date" bson:"date"`
	Comment    string    `json:"comment" bson:"comment"`
}

type Storage

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

func NewStorage(cfg *viper.Viper) (Storage, error)

type Vehicle

type Vehicle struct {
	ID             string         `json:"id" bson:"_id"`
	Type           string         `json:"type"`
	Namespace      string         `json:"namespace"`
	Administrators []string       `json:"administrators"`
	Data           map[string]any `json:"data"`
	Metadata       map[string]any `json:"metadata"`

	Bookings []Booking
}

func (Vehicle) Free

func (v Vehicle) Free(start time.Time, end time.Time) bool

func (Vehicle) MatchesFilters

func (v Vehicle) MatchesFilters(filters VehicleFilters) bool

type VehicleFilters

type VehicleFilters struct {
	Types          []string
	Administrators []string
	AvailableFrom  time.Time
	AvailableTo    time.Time
	IncludeDeleted bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL