bikerental

package
v0.0.0-...-a53416d Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bike

type Bike struct {
	ID        string
	ModelName string
	Weight    float64
	// PricePerHour in eurocents
	PricePerHour int
}

Bike represents a bike for rent.

func (*Bike) Validate

func (b *Bike) Validate() error

Validate validates bike data.

type BikeIncidentsInfo

type BikeIncidentsInfo struct {
	Location          Location
	Proximity         float64
	NumberOfIncidents int
}

BikeIncidentsInfo represents information about bike incidents within a square of size `proximity`, centered at `location`.

type BikeIncidentsRequest

type BikeIncidentsRequest struct {
	// Location defines center point of square in which we search for incidents.
	Location Location
	// Proximity defines square size in km, in which we search for incidents.
	Proximity float64
}

BikeIncidentsRequest is a request for incidents data.

type BikeIncidentsService

type BikeIncidentsService interface {
	GetIncidents(context.Context, BikeIncidentsRequest) (*BikeIncidentsInfo, error)
}

BikeIncidentsService provides information about bike incidents.

type BikeService

type BikeService interface {
	List(context.Context) ([]Bike, error)
	Get(ctx context.Context, id string) (*Bike, error)
	Add(context.Context, Bike) (*Bike, error)
	Update(ctx context.Context, id string, b Bike) error
	Delete(ctx context.Context, id string) error
}

BikeService manages bikes.

type CreateReservationRequest

type CreateReservationRequest struct {
	BikeID    string
	Customer  Customer
	Location  Location
	StartTime time.Time
	EndTime   time.Time
}

CreateReservationRequest is a request for creating new reservation.

func (*CreateReservationRequest) Validate

func (r *CreateReservationRequest) Validate() error

Validate validates request data.

type Customer

type Customer struct {
	ID        string
	Type      CustomerType
	FirstName string
	Surname   string
	Email     string
}

Customer represents customer renting a bike.

func (Customer) Validate

func (c Customer) Validate() error

Validate validates customer data.

type CustomerType

type CustomerType int

CustomerType represents customer type.

const (
	CustomerTypeUnknown CustomerType = iota
	CustomerTypeIndividual
	CustomerTypeBusiness
)

Customer types.

type Discount

type Discount struct {
	// Amount is in eurocents.
	Amount int
}

Discount represents fixed discount for bike rental.

type DiscountRequest

type DiscountRequest struct {
	Customer Customer
	Location Location
	Bike     Bike
	// ReservationValue in eurocents.
	ReservationValue int
}

DiscountRequest is a request for determining a discount for a bike rental.

func (DiscountRequest) Validate

func (r DiscountRequest) Validate() error

Validate validates the request.

type DiscountResponse

type DiscountResponse struct {
	Discount Discount
}

DiscountResponse is a response with calculated discount.

type DiscountService

type DiscountService interface {
	CalculateDiscount(context.Context, DiscountRequest) (*DiscountResponse, error)
}

DiscountService provides methods for calculating discounts for a bike rentals.

type ListReservationsRequest

type ListReservationsRequest struct {
	BikeID    string
	StartTime time.Time
	EndTime   time.Time
}

ListReservationsRequest is a request for listing reservations.

func (*ListReservationsRequest) Validate

func (r *ListReservationsRequest) Validate() error

Validate validates request data.

type Location

type Location struct {
	Lat  float64
	Long float64
}

Location represents physical location coordinates.

func (*Location) String

func (l *Location) String() string

String returns string representation of location.

func (*Location) Validate

func (l *Location) Validate() error

Validate validates location attributes.

type Reservation

type Reservation struct {
	ID        string
	Status    ReservationStatus
	Customer  Customer
	Bike      Bike
	StartTime time.Time
	EndTime   time.Time

	// TotalValue is a total amount to pay by the customer in eurocents.
	TotalValue int

	// AppliedDiscount is amount of discount applied to total reservation value in eurocents.
	AppliedDiscount int
}

Reservation represents reservation for a bike. Values are in fixed currency, we won't deal with currencies in decimals here for simplicity.

func (Reservation) Validate

func (r Reservation) Validate() error

Validate validates reservation data.

type ReservationResponse

type ReservationResponse struct {
	Status ReservationStatus

	// Reason contains reason of responding with given status.
	// If status is "approved", it should be empty.
	Reason string

	// Reservation will be empty for statuses other than "approved".
	Reservation *Reservation
}

ReservationResponse is a response for create reservation request. If status is other than "approved", `Reservation` attribute will be nil.

type ReservationService

type ReservationService interface {
	GetBikeAvailability(ctx context.Context, bikeID string, startTime, endTime time.Time) (bool, error)
	ListReservations(ctx context.Context, req ListReservationsRequest) ([]Reservation, error)
	CreateReservation(ctx context.Context, req CreateReservationRequest) (*ReservationResponse, error)
	CancelReservation(ctx context.Context, bikeID string, id string) error
}

ReservationService provies methods for making reservations.

type ReservationStatus

type ReservationStatus string

ReservationStatus describes reservation status.

const (
	ReservationStatusEmpty    ReservationStatus = ""
	ReservationStatusRejected ReservationStatus = "rejected"
	ReservationStatusApproved ReservationStatus = "approved"
	ReservationStatusCanceled ReservationStatus = "canceled"
)

Reservation statuses.

type Weather

type Weather struct {
	Temperature float64
}

Weather represents weather data.

type WeatherRequest

type WeatherRequest struct {
	Location Location
}

WeatherRequest is a request for weather data in a location.

type WeatherService

type WeatherService interface {
	GetWeather(context.Context, WeatherRequest) (*Weather, error)
}

WeatherService provides weather data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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