parkings

package
v0.0.0-...-0fd7009 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const VelobikeAPIEndpointURI = "https://velobike.ru/ajax/parkings/"

Variables

This section is empty.

Functions

This section is empty.

Types

type DbStateRepository

type DbStateRepository struct {
	DB *gorm.DB
}

func ProvideDbStateRepository

func ProvideDbStateRepository(DB *gorm.DB) DbStateRepository

func (*DbStateRepository) FindAll

func (sr *DbStateRepository) FindAll() ([]State, error)

func (*DbStateRepository) FindByTimeRange

func (sr *DbStateRepository) FindByTimeRange(from, to time.Time) ([]State, error)

func (*DbStateRepository) GetLast

func (sr *DbStateRepository) GetLast() (State, error)

func (*DbStateRepository) Save

func (sr *DbStateRepository) Save(state State) error

func (*DbStateRepository) SaveAll

func (sr *DbStateRepository) SaveAll(states []State) error

type JsonStateRepository

type JsonStateRepository struct {
	// contains filtered or unexported fields
}

func ProvideJsonStateRepository

func ProvideJsonStateRepository(directory string) JsonStateRepository

func (*JsonStateRepository) SaveAll

func (sr *JsonStateRepository) SaveAll(states []State, currentTime time.Time) error

type Request

type Request struct {
	RawResponse    []byte
	ParsedResponse *VelobikeResponse
}

func NewRequest

func NewRequest() Request

func (*Request) Get

func (r *Request) Get() error

func (*Request) Parse

func (r *Request) Parse() error

type State

type State struct {
	ID                  uint64    `gorm:"primary_key;auto_increment" json:"-"`
	Time                time.Time `gorm:"index:time_idx"`
	IsLocked            bool
	IsFavourite         bool
	FreeElectricPlaces  uint8
	FreeOrdinaryPlaces  uint8
	FreePlaces          uint8
	TotalElectricPlaces uint8
	TotalOrdinaryPlaces uint8
	TotalPlaces         uint8
	Station             Station `gorm:"foreignkey:StationID"`
	StationID           string  `gorm:"type:char(5)"`
}

State contains information about the station at a specific point in time

func ToState

func ToState(item VelobikeResponseItem, time time.Time) State

func ToStates

func ToStates(response VelobikeResponse) []State

type Station

type Station struct {
	ID          string `gorm:"primary_key;index:station_idx;type:char(5)"`
	Name        string
	Address     string
	PositionLat float32
	PositionLon float32
	HasTerminal bool
}

Station contains information about Velobike station

type VelobikeResponse

type VelobikeResponse struct {
	Items []VelobikeResponseItem
	Time  time.Time `json:"-"`
}

VelobikeResponse structure is properly parsed JSON with request time added.

type VelobikeResponseItem

type VelobikeResponseItem struct {
	Address            string
	FreeElectricPlaces uint8
	FreeOrdinaryPlaces uint8
	FreePlaces         uint8
	HasTerminal        bool
	ID                 string
	IsFavourite        bool
	IsLocked           bool
	Name               string
	Position           struct {
		Lat float32
		Lon float32
	}
	StationTypes        []string
	TotalElectricPlaces uint8
	TotalOrdinaryPlaces uint8
	TotalPlaces         uint8
}

VelobikeResponseItem structure is properly parsed JSON item.

Jump to

Keyboard shortcuts

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