reservation

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: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomerRepository

type CustomerRepository interface {
	// Get returns customer by id.
	// Returns app.ErrNotFound if customer doesn't exist.
	Get(ctx context.Context, id string) (*bikerental.Customer, error)
}

CustomerRepository provides methods for reading customer data.

type ListReservationsQuery

type ListReservationsQuery struct {
	BikeID    string
	StartTime time.Time
	EndTime   time.Time
	Status    bikerental.ReservationStatus
	Limit     int
}

ListReservationsQuery is a set of filters for reservations result.

type Repository

type Repository interface {
	// List returns list of reservations matching request criteria.
	List(context.Context, ListReservationsQuery) ([]bikerental.Reservation, error)

	// Get returns a reservation by id.
	// Returns app.ErrNotFound if reservation doesn't exists.
	Get(ctx context.Context, id string) (*bikerental.Reservation, error)

	// Create creates new reservation for a bike.
	// If any reservation for this bike exists within given time range, will return bikerental.ConflictError.
	// Returns created reservation data with filled all ids.
	Create(context.Context, bikerental.Reservation) (*bikerental.Reservation, error)

	// SetStatus updates the status of the reservation by its id.
	// Returns app.ErrNotFound if reservation doesn't exists.
	SetStatus(ctx context.Context, id string, status bikerental.ReservationStatus) error
}

Repository provides methods for reading/writing reservation data.

type Service

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

Service provides methods for making reservations.

func NewService

func NewService(
	discountService bikerental.DiscountService,
	bikeService bikerental.BikeService,
	reservationsRepo Repository,
	customersRepo CustomerRepository,
) (*Service, error)

NewService creates new service instance.

func (*Service) CancelReservation

func (s *Service) CancelReservation(ctx context.Context, bikeID string, id string) error

CancelReservation removes reservation by id and bike id. Returns app.ErrNotFound if reservation doesn't exists.

func (*Service) CreateReservation

CreateReservation creates new reservation if possible. If creating reservation is not possible due to business logic or availability issues, this method returns valid response. If there are errors while processing request, returns nil and an error.

func (*Service) GetBikeAvailability

func (s *Service) GetBikeAvailability(ctx context.Context, bikeID string, startTime, endTime time.Time) (bool, error)

GetBikeAvailability returns true if bike with given id is available for rent in given time range.

func (*Service) ListReservations

ListReservations returns list of reservations matching request criteria.

Jump to

Keyboard shortcuts

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