rotation

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoState = errors.New("no state available")

ErrNoState is returned when there is no state information available for a rotation.

Functions

This section is empty.

Types

type DB

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

func NewDB

func NewDB(ctx context.Context, db *sql.DB) (*DB, error)

func (*DB) AddParticipant

func (db *DB) AddParticipant(ctx context.Context, p *Participant) (*Participant, error)

func (*DB) AddParticipantTx

func (db *DB) AddParticipantTx(ctx context.Context, tx *sql.Tx, p *Participant) (*Participant, error)

func (*DB) AddRotationUsersTx

func (db *DB) AddRotationUsersTx(ctx context.Context, tx *sql.Tx, rotationID string, userIDs []string) error

func (*DB) CreateRotation

func (db *DB) CreateRotation(ctx context.Context, r *Rotation) (*Rotation, error)

func (*DB) CreateRotationTx

func (db *DB) CreateRotationTx(ctx context.Context, tx *sql.Tx, r *Rotation) (*Rotation, error)

func (*DB) DeleteManyTx

func (db *DB) DeleteManyTx(ctx context.Context, tx *sql.Tx, ids []string) error

func (*DB) DeleteRotation

func (db *DB) DeleteRotation(ctx context.Context, id string) error

func (*DB) DeleteRotationParticipantsTx

func (db *DB) DeleteRotationParticipantsTx(ctx context.Context, tx *sql.Tx, partIDs []string) error

func (*DB) DeleteRotationTx

func (db *DB) DeleteRotationTx(ctx context.Context, tx *sql.Tx, id string) error

func (*DB) DeleteStateTx

func (db *DB) DeleteStateTx(ctx context.Context, tx *sql.Tx, rotationID string) error

func (*DB) FindAllParticipants

func (db *DB) FindAllParticipants(ctx context.Context, rotationID string) ([]Participant, error)

func (*DB) FindAllParticipantsByScheduleID

func (db *DB) FindAllParticipantsByScheduleID(ctx context.Context, scheduleID string) ([]Participant, error)

func (*DB) FindAllParticipantsTx

func (db *DB) FindAllParticipantsTx(ctx context.Context, tx *sql.Tx, rotationID string) ([]Participant, error)

func (*DB) FindAllRotations

func (db *DB) FindAllRotations(ctx context.Context) ([]Rotation, error)

func (*DB) FindAllRotationsByScheduleID

func (db *DB) FindAllRotationsByScheduleID(ctx context.Context, schedID string) ([]Rotation, error)

func (*DB) FindAllStateByScheduleID

func (db *DB) FindAllStateByScheduleID(ctx context.Context, scheduleID string) ([]State, error)

func (*DB) FindMany

func (db *DB) FindMany(ctx context.Context, ids []string) ([]Rotation, error)

func (*DB) FindParticipant

func (db *DB) FindParticipant(ctx context.Context, id string) (*Participant, error)

func (*DB) FindParticipantCount

func (db *DB) FindParticipantCount(ctx context.Context, id string) (int, error)

func (*DB) FindRotation

func (db *DB) FindRotation(ctx context.Context, id string) (*Rotation, error)

func (*DB) FindRotationForUpdateTx

func (db *DB) FindRotationForUpdateTx(ctx context.Context, tx *sql.Tx, rotationID string) (*Rotation, error)

func (*DB) IsParticipantActive

func (db *DB) IsParticipantActive(ctx context.Context, partID string) (bool, error)

func (*DB) MoveParticipant

func (db *DB) MoveParticipant(ctx context.Context, id string, newPos int) error

func (*DB) RemoveParticipant

func (db *DB) RemoveParticipant(ctx context.Context, id string) (string, error)

func (*DB) RemoveParticipantTx

func (db *DB) RemoveParticipantTx(ctx context.Context, tx *sql.Tx, id string) (string, error)

func (*DB) Search

func (db *DB) Search(ctx context.Context, opts *SearchOptions) ([]Rotation, error)

func (*DB) SetActiveIndexTx

func (db *DB) SetActiveIndexTx(ctx context.Context, tx *sql.Tx, rotID string, position int) error

func (*DB) SetActiveParticipant

func (db *DB) SetActiveParticipant(ctx context.Context, rotID string, partID string) error

func (*DB) State

func (db *DB) State(ctx context.Context, id string) (*State, error)

func (*DB) StateTx

func (db *DB) StateTx(ctx context.Context, tx *sql.Tx, id string) (*State, error)

func (*DB) UpdateParticipantUserIDTx

func (db *DB) UpdateParticipantUserIDTx(ctx context.Context, tx *sql.Tx, partID, userID string) error

func (*DB) UpdateRotation

func (db *DB) UpdateRotation(ctx context.Context, r *Rotation) error

func (*DB) UpdateRotationTx

func (db *DB) UpdateRotationTx(ctx context.Context, tx *sql.Tx, r *Rotation) error

type Participant

type Participant struct {
	ID         string `json:"id"`
	Position   int    `json:"position"`
	RotationID string `json:"rotation_id"`
	Target     assignment.Target
}

func (Participant) Normalize

func (p Participant) Normalize() (*Participant, error)

type ParticipantReader

type ParticipantReader interface {
	FindParticipant(ctx context.Context, id string) (*Participant, error)
	FindAllParticipants(ctx context.Context, rotationID string) ([]Participant, error)
	FindAllParticipantsTx(ctx context.Context, tx *sql.Tx, rotationID string) ([]Participant, error)
	FindAllParticipantsByScheduleID(ctx context.Context, scheduleID string) ([]Participant, error)
}

type ReadStateStore

type ReadStateStore interface {
	StateReader
	ParticipantReader
}

type ReadStore

type ReadStore interface {
	FindRotation(context.Context, string) (*Rotation, error)
	FindRotationForUpdateTx(context.Context, *sql.Tx, string) (*Rotation, error)
	FindAllRotations(context.Context) ([]Rotation, error)
	FindAllRotationsByScheduleID(context.Context, string) ([]Rotation, error)
	FindParticipantCount(context.Context, string) (int, error)
}

type Rotation

type Rotation struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`

	Type        Type      `json:"type"`
	Start       time.Time `json:"start"`
	ShiftLength int       `json:"shift_length"`
	// contains filtered or unexported fields
}

func (Rotation) EndTime

func (r Rotation) EndTime(t time.Time) time.Time

EndTime calculates the end of the "shift" that started at (or was active) at t.

It is guaranteed to occur after t.

func (Rotation) IsUserFavorite added in v0.23.0

func (r Rotation) IsUserFavorite() bool

func (Rotation) Normalize

func (r Rotation) Normalize() (*Rotation, error)

func (Rotation) StartTime

func (r Rotation) StartTime(t time.Time) time.Time

StartTime calculates the start of the "shift" that started at (or was active) at t. For daily and weekly rotations, start time will be the previous handoff time (from start).

type SearchCursor

type SearchCursor struct {
	Name       string `json:"n,omitempty"`
	IsFavorite bool   `json:"f,omitempty"`
}

SearchCursor is used to indicate a position in a paginated list.

type SearchOptions

type SearchOptions struct {
	Search string       `json:"s,omitempty"`
	After  SearchCursor `json:"a,omitempty"`

	// Omit specifies a list of rotation IDs to exclude from the results
	Omit []string `json:"o,omitempty"`

	Limit int `json:"-"`

	// FavoritesOnly controls filtering the results to those marked as favorites by FavoritesUserID.
	FavoritesOnly bool `json:"b,omitempty"`

	// FavoritesFirst indicates that rotations marked as favorite (by FavoritesUserID) should be returned first (before any non-favorites).
	FavoritesFirst bool `json:"f,omitempty"`

	//FavoritesUserID is the userID associated with the rotation favorite
	FavoritesUserID string `json:"u,omitempty"`
}

SearchOptions allow filtering and paginating the list of rotations.

type State

type State struct {
	RotationID    string
	ParticipantID string
	Position      int
	ShiftStart    time.Time
}

func (State) Normalize

func (s State) Normalize() (*State, error)

type StateReader

type StateReader interface {
	State(context.Context, string) (*State, error)
	StateTx(context.Context, *sql.Tx, string) (*State, error)
	FindAllStateByScheduleID(context.Context, string) ([]State, error)
}

type StateStore

type StateStore interface {
	ReadStore
	StateReader
	ParticipantReader
}

type Store

type Store interface {
	ReadStore
	ReadStateStore
	CreateRotation(context.Context, *Rotation) (*Rotation, error)
	CreateRotationTx(context.Context, *sql.Tx, *Rotation) (*Rotation, error)
	UpdateRotation(context.Context, *Rotation) error
	UpdateRotationTx(context.Context, *sql.Tx, *Rotation) error
	DeleteRotation(context.Context, string) error
	DeleteRotationTx(context.Context, *sql.Tx, string) error
	DeleteManyTx(context.Context, *sql.Tx, []string) error

	AddParticipant(context.Context, *Participant) (*Participant, error)
	AddParticipantTx(context.Context, *sql.Tx, *Participant) (*Participant, error)
	RemoveParticipant(context.Context, string) (rotationID string, err error)
	RemoveParticipantTx(context.Context, *sql.Tx, string) (rotationID string, err error)
	MoveParticipant(context.Context, string, int) error
	IsParticipantActive(context.Context, string) (bool, error)
	SetActiveParticipant(ctx context.Context, rotationID, participantID string) error
	SetActiveIndexTx(ctx context.Context, tx *sql.Tx, rotID string, position int) error
	FindMany(context.Context, []string) ([]Rotation, error)
	Search(context.Context, *SearchOptions) ([]Rotation, error)

	AddRotationUsersTx(ctx context.Context, tx *sql.Tx, rotationID string, userIDs []string) error
	DeleteRotationParticipantsTx(ctx context.Context, tx *sql.Tx, partIDs []string) error
	UpdateParticipantUserIDTx(ctx context.Context, tx *sql.Tx, partID, userID string) error
	DeleteStateTx(ctx context.Context, tx *sql.Tx, rotationID string) error
}

type Type

type Type string
const (
	TypeWeekly Type = "weekly"
	TypeDaily  Type = "daily"
	TypeHourly Type = "hourly"
)

func (Type) MarshalGQL

func (t Type) MarshalGQL(w io.Writer)

MarshalGQL implements the graphql.Marshaler interface

func (*Type) Scan

func (r *Type) Scan(value interface{}) error

Scan handles reading a Role from the DB format

func (*Type) UnmarshalGQL

func (t *Type) UnmarshalGQL(v interface{}) error

UnmarshalGQL implements the graphql.Marshaler interface

func (Type) Value

func (r Type) Value() (driver.Value, error)

Value converts the Role to the DB representation

Jump to

Keyboard shortcuts

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