training

package
v0.0.0-...-e173b71 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Trainer  = UserType{"trainer"}
	Attendee = UserType{"attendee"}
)
View Source
var ErrNoRescheduleRequested = errors.New("no training reschedule was requested yet")
View Source
var ErrNoteTooLong = commonerrors.NewIncorrectInputError("Note too long", "note-too-long")
View Source
var ErrTrainingAlreadyCanceled = errors.New("training is already canceled")

Functions

func CanUserSeeTraining

func CanUserSeeTraining(user User, training Training) error

func CancelBalanceDelta

func CancelBalanceDelta(tr Training, cancelingUserType UserType) int

CancelBalanceDelta return trainings balance delta that should be adjusted after training cancellation.

Types

type CantRescheduleBeforeTimeError

type CantRescheduleBeforeTimeError struct {
	TrainingTime time.Time
}

func (CantRescheduleBeforeTimeError) Error

type ForbiddenToSeeTrainingError

type ForbiddenToSeeTrainingError struct {
	RequestingUserUUID string
	TrainingOwnerUUID  string
}

func (ForbiddenToSeeTrainingError) Error

type NotFoundError

type NotFoundError struct {
	TrainingUUID string
}

func (NotFoundError) Error

func (e NotFoundError) Error() string

type Repository

type Repository interface {
	AddTraining(ctx context.Context, tr *Training) error
	GetTraining(ctx context.Context, trainingUUID string, user User) (*Training, error)
	UpdateTraining(
		ctx context.Context,
		trainingUUID string,
		user User,
		updateFn func(ctx context.Context, tr *Training) (*Training, error),
	) error
}

type Training

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

func NewTraining

func NewTraining(uuid string, userUUID string, userName string, trainingTime time.Time) (*Training, error)

func UnmarshalTrainingFromDatabase

func UnmarshalTrainingFromDatabase(
	uuid string,
	userUUID string,
	userName string,
	trainingTime time.Time,
	notes string,
	canceled bool,
	proposedNewTime time.Time,
	moveProposedBy UserType,
) (*Training, error)

UnmarshalTrainingFromDatabase unmarshals Training from the database.

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

func (*Training) ApproveReschedule

func (t *Training) ApproveReschedule(userType UserType) error

func (Training) CanBeCanceledForFree

func (t Training) CanBeCanceledForFree() bool

func (*Training) Cancel

func (t *Training) Cancel() error

func (Training) IsCanceled

func (t Training) IsCanceled() bool

func (*Training) IsRescheduleProposed

func (t *Training) IsRescheduleProposed() bool

func (Training) MovedProposedBy

func (t Training) MovedProposedBy() UserType

func (Training) Notes

func (t Training) Notes() string

func (*Training) ProposeReschedule

func (t *Training) ProposeReschedule(newTime time.Time, proposerType UserType)

func (Training) ProposedNewTime

func (t Training) ProposedNewTime() time.Time

func (*Training) RejectReschedule

func (t *Training) RejectReschedule() error

func (*Training) RescheduleTraining

func (t *Training) RescheduleTraining(newTime time.Time) error

func (Training) Time

func (t Training) Time() time.Time

func (Training) UUID

func (t Training) UUID() string

func (*Training) UpdateNotes

func (t *Training) UpdateNotes(notes string) error

func (Training) UserName

func (t Training) UserName() string

func (Training) UserUUID

func (t Training) UserUUID() string

type User

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

func MustNewUser

func MustNewUser(userUUID string, userType UserType) User

func NewUser

func NewUser(userUUID string, userType UserType) (User, error)

func (User) IsEmpty

func (u User) IsEmpty() bool

func (User) Type

func (u User) Type() UserType

func (User) UUID

func (u User) UUID() string

type UserType

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

UserType is enum-like type By using struct with hidden field, we ensure immutability instead of declaring string as a UserType and using constants

func NewUserTypeFromString

func NewUserTypeFromString(userType string) (UserType, error)

func (UserType) IsZero

func (u UserType) IsZero() bool

func (UserType) String

func (u UserType) String() string

Jump to

Keyboard shortcuts

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