summaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
authorJulian Jørgensen <julian@jtle.dk>2024-05-24 23:33:49 +0200
committerJulian Jørgensen <julian@jtle.dk>2024-05-24 23:33:49 +0200
commit6cdd02af0684500b5376d4d4a08feb796fdaf889 (patch)
tree7ffb2ded2251fef175f2c0ce6dfbea978152e063 /db.go
parenteabd0e769c2bfef7a7aa748d794675d3ff7a920b (diff)
Add date stuff
Diffstat (limited to 'db.go')
-rw-r--r--db.go31
1 files changed, 19 insertions, 12 deletions
diff --git a/db.go b/db.go
index a1b0c33..45296d6 100644
--- a/db.go
+++ b/db.go
@@ -8,7 +8,7 @@ import (
type Database interface {
GetTracking() (*Entry, error)
GetEntries() ([]*Entry, error)
- QueryEntry(id *int) ([]*Entry, error)
+ QueryEntry(id *int, date *Date) ([]*Entry, error)
StartNewEntry(now time.Time, task *Entry) (*Entry, error)
StopEntry(now time.Time) error
SaveEntry(task *Entry) (*Entry, error)
@@ -49,12 +49,16 @@ func (db *InMemDb) GetEntries() ([]*Entry, error) {
return res, nil
}
-func (db *InMemDb) QueryEntry(id *int) ([]*Entry, error) {
+func (db *InMemDb) QueryEntry(id *int, date *Date) ([]*Entry, error) {
res := make([]*Entry, 0, 1)
for _, entry := range db.entries {
- if id != nil && entry.Id == *id {
- res = append(res, entry)
+ if id != nil && entry.Id != *id {
+ continue
+ }
+ if date != nil && entry.Date != *date {
+ continue
}
+ res = append(res, entry)
}
return res, nil
@@ -65,6 +69,7 @@ func (db *InMemDb) StartNewEntry(now time.Time, task *Entry) (*Entry, error) {
Id: len(db.entries),
From: task.From,
To: nil,
+ Date: DateFromStd(now),
Tag: task.Tag,
Comment: task.Comment,
}
@@ -77,6 +82,7 @@ func (db *InMemDb) StartNewEntry(now time.Time, task *Entry) (*Entry, error) {
db.entries = append(db.entries, newTask)
db.StopEntry(now)
db.current = newTask
+
return newTask, nil
}
@@ -91,20 +97,21 @@ func (db *InMemDb) StopEntry(now time.Time) error {
return nil
}
-func (db *InMemDb) SaveEntry(task *Entry) (*Entry, error) {
- if task.Id < 0 || task.Id >= len(db.entries) {
- copyTask := *task
+func (db *InMemDb) SaveEntry(entry *Entry) (*Entry, error) {
+ if entry.Id < 0 || entry.Id >= len(db.entries) {
+ copyTask := *entry
copyTask.Id = len(db.entries)
db.entries = append(db.entries, &copyTask)
return &copyTask, nil
}
- existent := db.entries[task.Id]
- existent.Comment = task.Comment
- existent.Tag = task.Tag
- existent.From = task.From
- existent.To = task.To
+ existent := db.entries[entry.Id]
+ existent.Comment = entry.Comment
+ existent.Tag = entry.Tag
+ existent.From = entry.From
+ existent.To = entry.To
+ existent.Date = entry.Date
return existent, nil
}