Documentation
¶
Index ¶
- type CustomerRepository
- type ListReservationsQuery
- type Repository
- type Service
- func (s *Service) CancelReservation(ctx context.Context, bikeID string, id string) error
- func (s *Service) CreateReservation(ctx context.Context, req bikerental.CreateReservationRequest) (*bikerental.ReservationResponse, error)
- func (s *Service) GetBikeAvailability(ctx context.Context, bikeID string, startTime, endTime time.Time) (bool, error)
- func (s *Service) ListReservations(ctx context.Context, req bikerental.ListReservationsRequest) ([]bikerental.Reservation, error)
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 ¶
CancelReservation removes reservation by id and bike id. Returns app.ErrNotFound if reservation doesn't exists.
func (*Service) CreateReservation ¶
func (s *Service) CreateReservation(ctx context.Context, req bikerental.CreateReservationRequest) (*bikerental.ReservationResponse, error)
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 ¶
func (s *Service) ListReservations(ctx context.Context, req bikerental.ListReservationsRequest) ([]bikerental.Reservation, error)
ListReservations returns list of reservations matching request criteria.