carsuc

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package carsuc contains the cars UseCase which supports the cars related use cases. Currently, two uses cases are supported:

  1. Riding a car,
  2. Parking a car.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(uc *UseCase) error

Option is a functional option for the cars use case.

func WithOldParkingMethodDelay

func WithOldParkingMethodDelay(delay time.Duration) Option

WithOldParkingMethodDelay option configures a cars UseCase instance in order to incur as much as the given delay during the old-method parking operations. This option may be passed to the New() function.

type UseCase

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

UseCase represents a cars use case. It holds a database connection pool, the cars repository instance (to be guided with the DB pool), and the cars use case specific settings.

func New

func New(p repo.Pool, c repo.Cars, opts ...Option) (*UseCase, error)

New instantiates a cars use case. Required parameters are passed individually, so caller has to provision them and whenever they change, caller will notice and fix them due to a compilation error. Optional parameters are passed as a series of functional options in order to facilitate their validation and flexibility.

func (*UseCase) Park

func (cars *UseCase) Park(ctx context.Context, cid uuid.UUID, mode model.ParkingMode) (car *model.Car, err error)

Park use case tries to park the cid car using the mode parking mode. The new parking mode works quickly while the old method incurs delay based on the configuration. It returns the updated car model and possible errors.

func (*UseCase) Ride

func (cars *UseCase) Ride(ctx context.Context, cid uuid.UUID, destination model.Coordinate) (car *model.Car, err error)

Ride use case unparks the cid car and moves it to the given destination geographical location. Updated car model and possible errors are returned.

Jump to

Keyboard shortcuts

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