summaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
authorJulian Jørgensen <julian@jtle.dk>2024-05-25 11:53:43 +0200
committerJulian Jørgensen <julian@jtle.dk>2024-05-25 11:53:43 +0200
commit2610f9b67e4a915859c029da9b17e9d262b6564e (patch)
tree4504bf2d995703f583fff199b1ae7e54eef4e432 /db.go
parent6cdd02af0684500b5376d4d4a08feb796fdaf889 (diff)
Add task ui and editingold
Diffstat (limited to 'db.go')
-rw-r--r--db.go42
1 files changed, 30 insertions, 12 deletions
diff --git a/db.go b/db.go
index 45296d6..363bc93 100644
--- a/db.go
+++ b/db.go
@@ -19,9 +19,9 @@ type Database interface {
}
type InMemDb struct {
- entries []*Entry
+ entries []*Entry
current *Entry
- tasks []*Task
+ tasks []*Task
}
var (
@@ -30,7 +30,7 @@ var (
)
func NewInMemDb() Database {
- return &InMemDb {
+ return &InMemDb{
entries: []*Entry{},
current: nil,
}
@@ -65,12 +65,12 @@ func (db *InMemDb) QueryEntry(id *int, date *Date) ([]*Entry, error) {
}
func (db *InMemDb) StartNewEntry(now time.Time, task *Entry) (*Entry, error) {
- newTask := &Entry {
- Id: len(db.entries),
- From: task.From,
- To: nil,
- Date: DateFromStd(now),
- Tag: task.Tag,
+ newTask := &Entry{
+ Id: len(db.entries),
+ From: task.From,
+ To: nil,
+ Date: DateFromStd(now),
+ Tag: task.Tag,
Comment: task.Comment,
}
@@ -139,8 +139,26 @@ func (db *InMemDb) QueryTask(id *int, group *string, ident *string) ([]*Task, er
res = append(res, task)
}
- return res, ErrNotFound
+ return res, nil
}
-func (db *InMemDb) SaveTask(task *Task) (*Task, error) {
- return nil, nil
+func (db *InMemDb) SaveTask(task *Task) (newTask *Task, err error) {
+ var tasks []*Task
+
+ tasks, err = db.QueryTask(&task.Id, nil, nil)
+ if err != nil {
+ return
+ }
+ if len(tasks) > 0 {
+ newTask = tasks[0]
+ newTask.Text = task.Text
+ newTask.Group = task.Group
+ newTask.Ident = task.Ident
+ } else {
+ taskCopy := *task
+ taskCopy.Id = len(db.tasks)
+ db.tasks = append(db.tasks, &taskCopy)
+ newTask = &taskCopy
+ }
+
+ return
}