gotime: github.com/nanohard/gotime/models Index | Files

package models

import "github.com/nanohard/gotime/models"

Index

Package Files

db.go entry.go project.go task.go

Constants

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

Variables

var DB *gorm.DB

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

var Setting setting

Setting will contain the only row from the settings table.

func AllEntries Uses

func AllEntries(t Task) []Entry

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

func AllProjects Uses

func AllProjects() []Project

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

func AllTasks Uses

func AllTasks(p Project) []Task

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

func InitDB Uses

func InitDB()

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

func TimeIn Uses

func TimeIn(t time.Time) string

TimeIn turns a time object into a datetime string.

func TimeOut Uses

func TimeOut(s string) time.Time

TimeOut turns a datetime string into a time object.

type Entry Uses

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 GetEntry Uses

func GetEntry(n string) Entry

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

func StartEntry Uses

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 Uses

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 Uses

func (e Entry) Delete()

Delete one entry.

func (Entry) HoursMinutes Uses

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

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

type Project Uses

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 Uses

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 GetProject Uses

func GetProject(n string) Project

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

func UpdateProject Uses

func UpdateProject(p Project) Project

UpdateProject will update the project with values defined outside.

func (Project) Delete Uses

func (p Project) Delete()

Delete one project and its children.

func (Project) HoursMinutes Uses

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 Uses

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 Uses

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 GetTask Uses

func GetTask(n string) Task

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

func (Task) Delete Uses

func (t Task) Delete()

Delete one task and its children.

func (Task) HoursMinutes Uses

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

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

Package models imports 5 packages (graph) and is imported by 1 packages. Updated 2017-08-29. Refresh now. Tools for package owners.