TaskFlow/viewmodels/viewmodels.go

79 lines
1.1 KiB
Go
Raw Normal View History

2015-11-13 17:04:42 +08:00
package viewmodels
import (
"github.com/thewhitetulip/task/db"
"github.com/thewhitetulip/task/types"
)
2015-11-14 18:56:53 +08:00
func GetTasks(status string) []types.Task {
return db.GetTasks(status)
2015-11-13 17:04:42 +08:00
}
2015-11-13 21:11:30 +08:00
func SearchTask(query string) []types.Task {
2015-11-13 17:04:42 +08:00
return db.SearchTask(query)
}
func AddTask(title, content string) bool {
err := db.AddTask(title, content)
2015-11-13 21:11:30 +08:00
if err != nil {
2015-11-13 17:04:42 +08:00
return false
}
return true
}
2015-11-14 18:56:53 +08:00
func TrashTask(id int) bool {
err := db.TrashTask(id)
if err != nil {
return false
}
return true
}
2015-11-13 17:04:42 +08:00
func RestoreTask(id int) bool {
err := db.RestoreTask(id)
if err != nil {
return false
}
return true
}
func DeleteTask(id int) bool {
err := db.DeleteTask(id)
if err != nil {
return false
}
return true
}
2015-11-13 21:11:30 +08:00
func DeleteAll() bool {
2015-11-13 17:04:42 +08:00
err := db.DeleteAll()
2015-11-13 21:11:30 +08:00
if err != nil {
2015-11-13 17:04:42 +08:00
return false
}
return true
}
2015-11-14 18:56:53 +08:00
func CompleteTask(id int) bool {
err := db.CompleteTask(id)
2015-11-13 17:04:42 +08:00
if err != nil {
return false
}
return true
}
2015-11-13 21:11:30 +08:00
func GetTaskById(id int) types.Task {
2015-11-13 17:04:42 +08:00
return db.GetTaskById(id)
}
2015-11-13 21:11:30 +08:00
func UpdateTask(id int, title string, content string) bool {
2015-11-13 17:04:42 +08:00
err := db.UpdateTask(id, title, content)
if err != nil {
return false
}
return true
}
2015-11-13 21:11:30 +08:00
func Close() {
2015-11-13 17:04:42 +08:00
db.Close()
}