Documentation ¶
Index ¶
- type Bike
- type BikeIncidentsInfo
- type BikeIncidentsRequest
- type BikeIncidentsService
- type BikeService
- type CreateReservationRequest
- type Customer
- type CustomerType
- type Discount
- type DiscountRequest
- type DiscountResponse
- type DiscountService
- type ListReservationsRequest
- type Location
- type Reservation
- type ReservationResponse
- type ReservationService
- type ReservationStatus
- type Weather
- type WeatherRequest
- type WeatherService
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.
type BikeIncidentsInfo ¶
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.
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 ¶
ListReservationsRequest is a request for listing reservations.
func (*ListReservationsRequest) Validate ¶
func (r *ListReservationsRequest) Validate() error
Validate validates request data.
type Location ¶
Location represents physical location coordinates.
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 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.