Documentation ¶
Index ¶
- Variables
- type Availability
- type Factory
- func (f Factory) Config() FactoryConfig
- func (f Factory) IsZero() bool
- func (f Factory) NewAvailableHour(hour time.Time) (*Hour, error)
- func (f Factory) NewNotAvailableHour(hour time.Time) (*Hour, error)
- func (f Factory) UnmarshalHourFromDatabase(hour time.Time, availability Availability) (*Hour, error)
- type FactoryConfig
- type Hour
- func (h Hour) Availability() Availability
- func (h *Hour) CancelTraining() error
- func (h Hour) HasTrainingScheduled() bool
- func (h Hour) IsAvailable() bool
- func (h *Hour) MakeAvailable() error
- func (h *Hour) MakeNotAvailable() error
- func (h *Hour) ScheduleTraining() error
- func (h *Hour) Time() time.Time
- type Repository
- type TooDistantDateError
- type TooEarlyHourError
- type TooLateHourError
Constants ¶
This section is empty.
Variables ¶
var ( Available = Availability{"available"} NotAvailable = Availability{"not_available"} TrainingScheduled = Availability{"training_scheduled"} )
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") )
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) NewNotAvailableHour ¶
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 ¶
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 (Hour) HasTrainingScheduled ¶
func (Hour) IsAvailable ¶
func (*Hour) MakeAvailable ¶
func (*Hour) MakeNotAvailable ¶
func (*Hour) ScheduleTraining ¶
type Repository ¶
type TooDistantDateError ¶
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 ¶
func (TooEarlyHourError) Error ¶
func (e TooEarlyHourError) Error() string
type TooLateHourError ¶
func (TooLateHourError) Error ¶
func (e TooLateHourError) Error() string