Documentation ¶
Index ¶
- Constants
- Variables
- type Database
- func (d *Database) AddTodoLabel(ctx context.Context, todo *Todo, label *Label) error
- func (d *Database) ChangeStatus(ctx context.Context, todo *Todo, oldStatus, newStatus *Status) error
- func (d *Database) Close() error
- func (d *Database) MoveDown(ctx context.Context, todo *Todo) error
- func (d *Database) MoveToBottom(ctx context.Context, todo *Todo) error
- func (d *Database) MoveToTop(ctx context.Context, todo *Todo) error
- func (d *Database) MoveUp(ctx context.Context, todo *Todo) error
- func (d *Database) NewLabel(ctx context.Context, name string) (*Label, error)
- func (d *Database) NewTodo(ctx context.Context, title, description string) (*Todo, error)
- func (d *Database) RemoveTodoLabel(ctx context.Context, todo *Todo, label *Label) error
- func (d *Database) UpdateLabel(ctx context.Context, label *Label, name string) error
- func (d *Database) UpdateTodo(ctx context.Context, todo *Todo, title, description string) error
- type Label
- type Status
- type Todo
Constants ¶
const ( StatusClosed = "closed" StatusOpen = "open" StatusDone = "done" StatusOnHold = "on_hold" StatusAbandoned = "abandoned" )
These constants refer to the statuses supported by the app.
const MaxClosedTodos = 5
MaxClosedTodos defines the size of the closed todo list. This is intended to constrict work to items on this list, which encourages focus and prioritization.
Variables ¶
var ( // ErrMaxClosedTodos is returned from ChangeStatus when attempting to move a todo to the closed list when it is // full (i.e., it already has MaxClosedTodos todos). ErrMaxClosedTodos = fmt.Errorf( "there are already %d closed todos; complete or abandon something before starting something new", MaxClosedTodos, ) // ErrInvalidTodoMoveNoStatusChange is returned from ChangeStatus when the old and new statuses are the same. ErrInvalidTodoMoveNoStatusChange = errors.New("cannot move a todo from one status to itself") // ErrInvalidTodoMove is returned from ChangeStatus when the old and new statuses are the same. ErrInvalidTodoMove = errors.New("cannot move a todo") // ErrCantMoveFirstTodoUp is returned from MoveUp when the first todo is moved up. ErrCantMoveFirstTodoUp = errors.New("cannot move up the first todo") // ErrCantMoveLastTodoDown is returned from MoveDown when the last todo is moved down. ErrCantMoveLastTodoDown = errors.New("cannot move down the last todo") // ErrNilTodo is returned when a modification is attempted on a nil Todo. ErrNilTodo = errors.New("no Todo is currently selected") // ErrEmptyTitle is returned when a new or modified todo has no title. ErrEmptyTitle = errors.New("Todo title cannot be empty") )
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database struct { Statuses map[string]*Status Labels []*Label Todos []*Todo // contains filtered or unexported fields }
Database manages the db connection and the state of the system.
func NewDatabase ¶
NewDatabase connects to the sqlite database at the given filename, initializes the structure if not present, and loads existing data into memory.
func (*Database) AddTodoLabel ¶
AddTodoLabel adds a Label to a Todo.
func (*Database) ChangeStatus ¶
func (d *Database) ChangeStatus(ctx context.Context, todo *Todo, oldStatus, newStatus *Status) error
ChangeStatus moves a Todo from one status to another.
func (*Database) MoveDown ¶
MoveDown moves a Todo one position down in the list, meaning it increases the ranking by 1 and reduces the ranking of the next Todo. If the last Todo is passed, return ErrCantMoveLastTodoDown.
func (*Database) MoveToBottom ¶
MoveToBottom moves a Todo to the bottom of the list and moves everything else up (meaning it decreases all lower rankings by 1) If the last Todo is passed, return ErrCantMoveLastTodoDown.
func (*Database) MoveToTop ¶
MoveToTop moves a Todo to the top of the list and moves everything else down (meaning it increases all higher rankings by 1) If the first Todo is passed, return ErrCantMoveFirstTodoUp.
func (*Database) MoveUp ¶
MoveUp moves a Todo one position up in the list, meaning it reduces the ranking by 1. and increases the ranking of the previous Todo. If the last Todo is passed, return ErrCantMoveFirstTodoUp.
func (*Database) NewTodo ¶
NewTodo creates a new Todo with the given title and description; the Todo is added at the end of the open list.
func (*Database) RemoveTodoLabel ¶
RemoveTodoLabel removes a Label from a Todo.
func (*Database) UpdateLabel ¶
UpdateLabel updates the label name.
type Todo ¶
type Todo struct { Title string Description string Labels []*Label // Rank is maintained within each status. It starts at 0 and increments by 1. // When a Todo is moved to a different status, it is appended to the list, so it has the // highest rank in that list. Rank int Status *Status // TODO (medium): populate timestamps! CreatedDatetime *time.Time UpdatedDatetime *time.Time // contains filtered or unexported fields }
Todo contains individual todo entries and associated labels from the todo_labels table.