Made use of SetIDFromDatabaseKey

This commit is contained in:
マリウス 2020-10-15 22:44:36 +01:00
parent 1f2c1d52aa
commit ee499f5c3e
No known key found for this signature in database
GPG key ID: C228EF0A530AF06F

View file

@ -4,7 +4,6 @@ import (
"os" "os"
"log" "log"
"errors" "errors"
"strings"
"encoding/json" "encoding/json"
"github.com/tidwall/buntdb" "github.com/tidwall/buntdb"
"github.com/google/uuid" "github.com/google/uuid"
@ -72,7 +71,9 @@ func (database *Database) GetEntry(user string, entryId string) (Entry, error) {
dberr := database.DB.View(func(tx *buntdb.Tx) error { dberr := database.DB.View(func(tx *buntdb.Tx) error {
tx.AscendKeys(user + ":entry:" + entryId, func(key, value string) bool { tx.AscendKeys(user + ":entry:" + entryId, func(key, value string) bool {
json.Unmarshal([]byte(value), &entry) json.Unmarshal([]byte(value), &entry)
entry.ID = (strings.Split(key, ":"))[2]
entry.SetIDFromDatabaseKey(key)
return true return true
}) })
@ -137,7 +138,7 @@ func (database *Database) ListEntries() ([]Entry, error) {
var entry Entry var entry Entry
json.Unmarshal([]byte(value), &entry) json.Unmarshal([]byte(value), &entry)
entry.ID = key entry.SetIDFromDatabaseKey(key)
entries = append(entries, entry) entries = append(entries, entry)
return true return true