hour

package
v0.0.0-...-56ef6d5 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Available         = Availability{"available"}
	NotAvailable      = Availability{"not_available"}
	TrainingScheduled = Availability{"training_scheduled"}
)
View Source
var (
	ErrTrainingScheduled   = errors.New("unable to modify hour, because scheduled training")
	ErrNoTrainingScheduled = errors.New("training is not scheduled")
	ErrHourNotAvailable    = errors.New("hour is not available")
)
View Source
var (
	ErrNotFullHour = errors.New("hour should be a full hour")
	ErrPastHour    = errors.New("cannot create hour from past")
)

Functions

This section is empty.

Types

type Availability

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

Availability is enum.

Using struct instead of `type Availability string` for enums allows us to ensure, that we have full control of what values are possible. With `type Availability string` you are able to create `Availability("i_can_put_anything_here")`

func NewAvailabilityFromString

func NewAvailabilityFromString(availabilityStr string) (Availability, error)

func (Availability) IsZero

func (h Availability) IsZero() bool

Every type in Go have zero value. In that case it's `Availability{}`. It's always a good idea to check if provided value is not zero!

func (Availability) String

func (h Availability) String() string

type Factory

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

func MustNewFactory

func MustNewFactory(fc FactoryConfig) Factory

func NewFactory

func NewFactory(fc FactoryConfig) (Factory, error)

func (Factory) Config

func (f Factory) Config() FactoryConfig

func (Factory) IsZero

func (f Factory) IsZero() bool

func (Factory) NewAvailableHour

func (f Factory) NewAvailableHour(hour time.Time) (*Hour, error)

func (Factory) NewNotAvailableHour

func (f Factory) NewNotAvailableHour(hour time.Time) (*Hour, error)

func (Factory) UnmarshalHourFromDatabase

func (f Factory) UnmarshalHourFromDatabase(hour time.Time, availability Availability) (*Hour, error)

UnmarshalHourFromDatabase unmarshals Hour from the database.

It should be used only for unmarshalling from the database! You can't use UnmarshalHourFromDatabase as constructor - It may put domain into the invalid state!

type FactoryConfig

type FactoryConfig struct {
	MaxWeeksInTheFutureToSet int
	MinUtcHour               int
	MaxUtcHour               int
}

func (FactoryConfig) Validate

func (f FactoryConfig) Validate() error

type Hour

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

func (Hour) Availability

func (h Hour) Availability() Availability

func (*Hour) CancelTraining

func (h *Hour) CancelTraining() error

func (Hour) HasTrainingScheduled

func (h Hour) HasTrainingScheduled() bool

func (Hour) IsAvailable

func (h Hour) IsAvailable() bool

func (*Hour) MakeAvailable

func (h *Hour) MakeAvailable() error

func (*Hour) MakeNotAvailable

func (h *Hour) MakeNotAvailable() error

func (*Hour) ScheduleTraining

func (h *Hour) ScheduleTraining() error

func (*Hour) Time

func (h *Hour) Time() time.Time

type Repository

type Repository interface {
	GetHour(ctx context.Context, hourTime time.Time) (*Hour, error)
	UpdateHour(
		ctx context.Context,
		hourTime time.Time,
		updateFn func(h *Hour) (*Hour, error),
	) error
}

type TooDistantDateError

type TooDistantDateError struct {
	MaxWeeksInTheFutureToSet int
	ProvidedDate             time.Time
}

If you have the error with a more complex context, it's a good idea to define it as a separate type. There is nothing worst, than error "invalid date" without knowing what date was passed and what is the valid value!

func (TooDistantDateError) Error

func (e TooDistantDateError) Error() string

type TooEarlyHourError

type TooEarlyHourError struct {
	MinUtcHour   int
	ProvidedTime time.Time
}

func (TooEarlyHourError) Error

func (e TooEarlyHourError) Error() string

type TooLateHourError

type TooLateHourError struct {
	MaxUtcHour   int
	ProvidedTime time.Time
}

func (TooLateHourError) Error

func (e TooLateHourError) Error() string

Jump to

Keyboard shortcuts

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