models

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2017 License: BSD-3-Clause, MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TL is the time layout we will use.
	TL = "2006-01-02 15:04"
)

Variables

View Source
var DB *gorm.DB

DB is the connection to gorm. Required to be exported so main.go can defer close the database.

View Source
var Setting setting

Setting will contain the only row from the settings table.

Functions

func InitDB

func InitDB()

InitDB will initialize the connection. It is used in main.go.

func TimeIn

func TimeIn(t time.Time) string

TimeIn turns a time object into a datetime string.

func TimeOut

func TimeOut(s string) time.Time

TimeOut turns a datetime string into a time object.

Types

type Entry

type Entry struct {
	gorm.Model
	Name      string `gorm:"index;unique;not null"`
	Details   string
	Start     time.Time
	End       time.Time
	Task      Task
	TaskID    uint `gorm:"index;not null"`
	Project   Project
	ProjectID uint `gorm:"index;not null"`
	TotalTime time.Duration
}

Entry model.

var CurrentEntry Entry

CurrentEntry holds the struct of the currently highlighted entry.

func AllEntries

func AllEntries(t Task) []Entry

AllEntries queries the database for, and returns, all entries after scanning them into a slice.

func GetEntry

func GetEntry(n string) Entry

GetEntry queries the database for, and returns, one entry after scanning it into the struct.

func StartEntry

func StartEntry(t Task, s time.Time) Entry

StartEntry queries the database for one entry by name. If the record exists then it is returned; else, it will create the record and return that one. It takes a task and start time as arguments.

func StopEntry

func StopEntry(e Entry, s time.Time, d string) Entry

StopEntry updates the entry with the stopped time, duration, and details. It takes an entry struct and stop time as arguments.

func (Entry) Delete

func (e Entry) Delete()

Delete one entry.

func (Entry) HoursMinutes

func (e Entry) HoursMinutes() (h int, m int)

HoursMinutes takes an Entry{} and returns its hours and minutes, both as ints.

type Project

type Project struct {
	gorm.Model
	Name        string `gorm:"type:varchar(100);unique;not null"`
	Description string
	Tasks       []Task
	Entries     []Entry
	TotalTime   time.Duration
}

Project model.

var CurrentProject Project

CurrentProject holds the struct of the currently highlighted project.

func AddProject

func AddProject(n string) Project

AddProject queries the database for one project by name (project names are unique). If the record exists then it is returned; else, it will create the record and return that one.

func AllProjects

func AllProjects() []Project

AllProjects queries the database for, and returns, all projects after scanning them into a slice of structs.

func GetProject

func GetProject(n string) Project

GetProject queries the database for, and returns, one project after scanning it into the struct.

func UpdateProject

func UpdateProject(p Project) Project

UpdateProject will update the project with values defined outside.

func (Project) Delete

func (p Project) Delete()

Delete one project and its children.

func (Project) HoursMinutes

func (p Project) HoursMinutes() (h int, m int)

HoursMinutes takes all entries for a project and returns its hours and minutes, both as ints.

type Task

type Task struct {
	gorm.Model
	Name        string `gorm:"not null"`
	Description string
	Entries     []Entry
	Project     Project
	ProjectID   uint `gorm:"index;not null"`
	TotalTime   time.Duration
}

Task model.

var CurrentTask Task

CurrentTask holds the struct of the currently highlighted task.

func AddTask

func AddTask(n string, p Project) Task

AddTask queries the database for one project by name. If the record exists then it is returned; else, it will create the record and return that one.

func AllTasks

func AllTasks(p Project) []Task

AllTasks queries the database for, and returns, all tasks after scanning them into a slice.

func GetTask

func GetTask(n string) Task

GetTask queries the database for, and returns, one task after scanning it into the struct.

func (Task) Delete

func (t Task) Delete()

Delete one task and its children.

func (Task) HoursMinutes

func (t Task) HoursMinutes() (h int, m int)

HoursMinutes takes all entries for a task and returns its hours and minutes, both as ints.

Jump to

Keyboard shortcuts

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