storage

package
v0.0.0-...-1e04dac Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2018 License: GPL-3.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBikeNotFound   = errors.New("bike not found")
	ErrNotImplemented = errors.New("not implemented")
)

Database based errors.

Functions

func NewContext

func NewContext(ctx context.Context, db Store) context.Context

NewContext adds the given Store to the Context.

Types

type Bike

type Bike struct {
	ID        int64
	PublicID  string
	Status    int
	Latitude  float64
	Longitude float64
}

Bike is the database representation of a models.Bike.

type BikeStore

type BikeStore interface {
	CreateBikes(ctx context.Context, bikes []Bike) ([]models.Bike, error)
	ListBikes(ctx context.Context, cursor string, limit int64) ([]models.Bike, error)
	FindBikeByPublicID(ctx context.Context, bikeID string) (*models.Bike, error)
	UpdateBikeLocation(ctx context.Context, bikeID string, lat, lng float64) error
	UnLockBikeByPublicID(ctx context.Context, bikeID string) (*models.Bike, error)
	LockBikeByPublicID(ctx context.Context, bikeID string) (*models.Bike, error)
	ListAllBikes(ctx context.Context, limit int64) ([]models.Bike, error)
}

BikeStore specifies how bike service persisted its data.

func BikeStoreFromContext

func BikeStoreFromContext(ctx context.Context) BikeStore

BikeStoreFromContext extracts a BikeStore from the Context.

type Location

type Location struct {
	ID        int64
	Latitude  float64
	Longitude float64
	TripID    string
	CreatedAt time.Time
}

Location is the database representation of a models.Location.

type Store

type Store interface {
	BikeStore
	TripStore

	Close(ctx context.Context) error
}

Store specifies how persistance is handled in the app.

func NewPostgresDatabase

func NewPostgresDatabase(ctx context.Context,
	config configuration.Database, logger logging.Logger) (Store, error)

NewPostgresDatabase return a valid Store with postgres.

type Trip

type Trip struct {
	ID        int64
	PublicID  string
	Status    int
	BikeID    string
	StartedAt time.Time
	EndedAt   pq.NullTime
}

Trip is the database representation of a models.Trip.

type TripStore

type TripStore interface {
	GetLocationsForTrip(ctx context.Context, tripID string) ([]models.Location, error)
	AddLocationToTrip(ctx context.Context, tripID string, lat, lng float64) error
	CreateTrip(ctx context.Context, bikeID string, lat, lng float64) (*models.Trip, error)
	EndTrip(ctx context.Context, tripID string, lat, lng float64) (*models.Trip, error)
}

TripStore specifies how trip service persisted its data.

func TripStoreFromContext

func TripStoreFromContext(ctx context.Context) TripStore

TripStoreFromContext extracts a TripStore from the Context.

Jump to

Keyboard shortcuts

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