usecase

package
v0.0.0-...-430e8a6 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSchedule

func AddSchedule(r ScheduleRepo, s *schedule.Schedule, checkSchedule chan<- bool) (ScheduleID, Error)

AddSchedule adds a new schedule

func AddTask

func AddTask(r TaskRepo, t *task.Task) (*TaskData, Error)

AddTask creates and adds a new task to the list

func CheckSchedules

func CheckSchedules(taskRepo TaskRepo, scheduleRepo ScheduleRepo) (time.Time, error)

CheckSchedules checks all schedules, determines all recurrences that have occurred, and when the next run is needed

func GetSchedule

func GetSchedule(r ScheduleRepo, id ScheduleID, uid user.ID) (*ScheduleData, Error)

GetSchedule returns a single schedule

func GetTask

func GetTask(r TaskRepo, id TaskID, uid user.ID) (*TaskData, Error)

GetTask gets a single task

Types

type Error

type Error interface {
	Code() ErrorCode
	Error() string
	Prefix(format string, a ...interface{}) Error
}

Error defines the custom use case error interface

func AddOrUpdateExternalUser

func AddOrUpdateExternalUser(r UserRepo, providerID string, externalID string, displayname string) (*user.User, Error)

AddOrUpdateExternalUser looks up a user by an external provider's ID, then either adds them or updates their displayname if needed

func AddRecurringTask

func AddRecurringTask(r ScheduleRepo, id ScheduleID, uid user.ID, rt schedule.RecurringTask) Error

AddRecurringTask adds a new recurring task to the schedule

func ClearCompletedTasks

func ClearCompletedTasks(r TaskRepo, uid user.ID) (int, Error)

ClearCompletedTasks clears all completed tasks, returning the number completed and an error

func ClearTask

func ClearTask(r TaskRepo, id TaskID, uid user.ID) (bool, Error)

ClearTask clears (removes) a single task, regardless of whether it has been completed

func CompleteTask

func CompleteTask(r TaskRepo, id TaskID, uid user.ID) (bool, Error)

CompleteTask completes an existing task

func GetExternalUser

func GetExternalUser(r UserRepo, providerID string, externalID string) (*user.User, Error)

GetExternalUser looks up a user by an external provider's ID, then returns it

func ListSchedules

func ListSchedules(r ScheduleRepo, uid user.ID) (map[ScheduleID]*schedule.Schedule, Error)

ListSchedules returns all schedules

func ListTasks

func ListTasks(r TaskRepo, uid user.ID) (map[TaskID]*task.Task, Error)

ListTasks returns all valid (uncleared) tasks

func NewError

func NewError(code ErrorCode, format string, a ...interface{}) Error

NewError formats and returns a use case error

func PauseSchedule

func PauseSchedule(r ScheduleRepo, id ScheduleID, uid user.ID, checkSchedule chan<- bool) Error

PauseSchedule pauses the schedule

func RemoveRecurringTask

func RemoveRecurringTask(r ScheduleRepo, id ScheduleID, uid user.ID, rt schedule.RecurringTask) Error

RemoveRecurringTask removes the recurring task at the specified index from the schedule

func RemoveSchedule

func RemoveSchedule(r ScheduleRepo, id ScheduleID, uid user.ID, checkSchedule chan<- bool) Error

RemoveSchedule removes a schedule

func UnpauseSchedule

func UnpauseSchedule(r ScheduleRepo, id ScheduleID, uid user.ID, checkSchedule chan<- bool) Error

UnpauseSchedule unpauses the schedule

type ErrorCode

type ErrorCode uint8

ErrorCode use case error type

const (
	ErrNone    ErrorCode = 0
	ErrUnknown ErrorCode = 1 << iota
	ErrRecordNotFound
	ErrDuplicateRecord
	ErrInvalidID
)

Use case error types

func (ErrorCode) String

func (ec ErrorCode) String() string

type ScheduleData

type ScheduleData struct {
	ScheduleID ScheduleID
	Schedule   *schedule.Schedule
}

ScheduleData contains application-level task info

type ScheduleID

type ScheduleID int64

ScheduleID is the persistent ID of the task

type ScheduleRepo

type ScheduleRepo interface {
	Get(ScheduleID) (*schedule.Schedule, Error)
	GetForUser(ScheduleID, user.ID) (*schedule.Schedule, Error)
	GetAll() (map[ScheduleID]*schedule.Schedule, Error)
	GetAllForUser(user.ID) (map[ScheduleID]*schedule.Schedule, Error)
	GetAllScheduled() (map[ScheduleID]*schedule.Schedule, Error)
	Add(*schedule.Schedule) (ScheduleID, Error)
	Update(ScheduleID, *schedule.Schedule) Error
}

ScheduleRepo defines the task repository interface required by use cases

type TaskData

type TaskData struct {
	TaskID TaskID
	Task   *task.Task
}

TaskData contains application-level task info

type TaskID

type TaskID int64

TaskID is the persistent ID of the task

type TaskRepo

type TaskRepo interface {
	GetForUser(TaskID, user.ID) (*task.Task, Error)
	GetAll() (map[TaskID]*task.Task, Error)
	GetAllForUser(user.ID) (map[TaskID]*task.Task, Error)
	Add(*task.Task) (TaskID, Error)
	Update(TaskID, *task.Task) Error
}

TaskRepo defines the task repository interface required by use cases

type UserRepo

type UserRepo interface {
	AddExternal(u *user.User, providerID string, externalID string) Error
	Update(*user.User) Error
	GetExternal(providerID string, externalID string) (*user.User, Error)
}

UserRepo defines the user repository interface required by use cases

Jump to

Keyboard shortcuts

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