From dbe231f710754f63602653208bf0564067f0c1dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Sat, 17 Oct 2020 21:14:34 +0100 Subject: [PATCH] Implemented UpdateEntry --- z/database.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/z/database.go b/z/database.go index 8f0d060..5dc2806 100644 --- a/z/database.go +++ b/z/database.go @@ -85,6 +85,24 @@ func (database *Database) GetEntry(user string, entryId string) (Entry, error) { return entry, dberr } +func (database *Database) UpdateEntry(user string, entry Entry) (string, error) { + entryJson, jsonerr := json.Marshal(entry) + if jsonerr != nil { + return entry.ID, jsonerr + } + + dberr := database.DB.Update(func(tx *buntdb.Tx) error { + _, _, seerr := tx.Set(user + ":entry:" + entry.ID, string(entryJson), nil) + if seerr != nil { + return seerr + } + + return nil + }) + + return entry.ID, dberr +} + func (database *Database) FinishEntry(user string, entry Entry) (string, error) { entryJson, jsonerr := json.Marshal(entry) if jsonerr != nil {