timeservice

package
v0.0.0-...-4d2825e Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyStarted = errors.New("already started")
	ErrNotStartedYet  = errors.New("not started yet")
	ErrNotEndedYet    = errors.New("not ended yet")
	ErrConflict       = errors.New("conflict")
)
View Source
var ErrInvalidDuration = errors.New("invalid duration")
View Source
var ErrInvalidMomentType = errors.New("invalid moment type")
View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type Day

type Day struct {
	Date    time.Time `json:"date"`
	Moments []Moment  `json:"moments"`
}

type Duration

type Duration struct {
	time.Duration
}

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) Scan

func (d *Duration) Scan(src interface{}) error

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(bytes []byte) error

func (Duration) Value

func (d Duration) Value() (driver.Value, error)

type List

type List struct {
	ID       int           `json:"id"`
	Name     string        `json:"name"`
	Settings *ListSettings `json:"settings,omitempty"`
}

type ListDayOptions

type ListDayOptions struct {
}

type ListDaysOption

type ListDaysOption func(*ListDayOptions)

type ListSettings

type ListSettings struct {
	DailyTime *Duration `json:"daily_time,omitempty"`
}

type Moment

type Moment struct {
	Type MomentType `json:"type"`
	Time time.Time  `json:"time"`
}

type MomentType

type MomentType int
const (
	MomentTypeStart MomentType = iota
	MomentTypeStartBreak
	MomentTypeEndBreak
	MomentTypeEnd
)

func (MomentType) MarshalJSON

func (t MomentType) MarshalJSON() ([]byte, error)

func (*MomentType) ReadStr

func (t *MomentType) ReadStr(str string) error

func (*MomentType) Scan

func (t *MomentType) Scan(src interface{}) error

func (MomentType) StrErr

func (t MomentType) StrErr() (string, error)

func (MomentType) String

func (t MomentType) String() string

TODO: add validation for MomentType enum

func (*MomentType) UnmarshalJSON

func (t *MomentType) UnmarshalJSON(bytes []byte) error

func (MomentType) Value

func (t MomentType) Value() (driver.Value, error)

type Repository

type Repository interface {
	AddList(ctx context.Context, list List) (int, error)
	GetLists(ctx context.Context) ([]List, error)
	GetListByID(ctx context.Context, listID int) (*List, error)
	UpdateList(ctx context.Context, list List) error
	DeleteListByID(ctx context.Context, listID int) error

	AddDay(ctx context.Context, listID int, day Day) error
	GetDays(ctx context.Context, listID int) ([]Day, error)
	GetDayByDate(ctx context.Context, listID int, date time.Time) (*Day, error)
	UpdateDay(ctx context.Context, listID int, day Day) error
	DeleteDayByDate(ctx context.Context, listID int, date time.Time) error
}

func NewRepository

func NewRepository(db *sqlx.DB, logger log.Logger) Repository

type Service

type Service interface {
	// lists
	AddList(ctx context.Context, name string, settings *ListSettings) (*List, error)
	GetLists(ctx context.Context) ([]List, error)
	GetList(ctx context.Context, listID int) (*List, error)
	UpdateList(ctx context.Context, listID int, name string, settings *ListSettings) (*List, error)
	DeleteList(ctx context.Context, listID int) error

	// days
	AddDay(ctx context.Context, listID int, date time.Time, moments []Moment) (*Day, error)
	GetDays(ctx context.Context, listID int, opts ...ListDaysOption) ([]Day, error)
	GetDay(ctx context.Context, listID int, date time.Time) (*Day, error)
	UpdateDay(ctx context.Context, listID int, date time.Time, moments []Moment) (*Day, error)
	DeleteDay(ctx context.Context, listID int, date time.Time) error

	// dynamic utility functions
	StartDay(ctx context.Context, listID int, timeStamp time.Time) error
	StartBreak(ctx context.Context, listID int, timeStamp time.Time) error
	EndBreak(ctx context.Context, listID int, timeStamp time.Time) error
	EndDay(ctx context.Context, listID int, timeStamp time.Time) error
}

func NewService

func NewService(repository Repository, logger log.Logger) Service

Jump to

Keyboard shortcuts

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