model

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

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

Go to latest
Published: Nov 27, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package model manages DB interactions as well as validates input

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTodo

func AddTodo(todoToAdd TodoItem)

AddTodo saves a todo item into the database.

func DeleteTodo

func DeleteTodo(todo_id uint)

DeleteTodo will delete the todo item with the given ID.

func GetAllTodoKinds

func GetAllTodoKinds() map[int]string

GetAllTodoKinds returns a map of TodoKinds and their string representations.

func InitDB

func InitDB()

InitDB will open the database and create the table if it doesn't exist.

func LogErr

func LogErr(err error)

LogErr fatally logs any non-nil error passed to it.

func MarkDone

func MarkDone(todo_id uint)

MarkDone will toggle the state of the todo item with the given ID.

func UpdateTodo

func UpdateTodo(newTodoInfo TodoItem)

UpdateTodo will modify a todo of a given ID to match the passed TodoItem

Types

type TodoItem

type TodoItem struct {
	TodoId uint
	Name   string
	Desc   string
	Kind   TodoKind
	State  TodoState
}

TODO look at having this later be restricted on how long name and desc can be? - maybe name is no more than 200 chars TodoItem represents an item in our todo list

func GetAllTodos

func GetAllTodos() []TodoItem

GetAllTodos returns all todos in the DB as a slice of TodoItems

func (TodoItem) GetValidKinds

func (ti TodoItem) GetValidKinds() map[int]string

GetValidKinds returns a slice of all valid kinds of todos

func (TodoItem) IsDone

func (ti TodoItem) IsDone() bool

IsDone returns true if the todo item is done

func (TodoItem) IsInProgress

func (ti TodoItem) IsInProgress() bool

IsInProgress returns true if the todo item is currently in progress

type TodoKind

type TodoKind int

TodoKind represents the todo item categories we'll allow

const (
	KindUncategorized TodoKind = iota - 1
	KindProject
	KindHomework
	KindReading
	KindStudy
)

func (TodoKind) String

func (tk TodoKind) String() string

Method to get a string representation of a kind of todo

type TodoState

type TodoState int

TodoState represents the state of a todo item. (ie whether it's done, being worked on, or not started)

const (
	StateInProgress TodoState = iota - 1
	StateTodo
	StateDone
)

func (TodoState) String

func (ts TodoState) String() string

Method to get a string representation of a TodoState

Jump to

Keyboard shortcuts

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