From 45fe5093d00543e8625ab23a5446c8c0b2d40ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Fri, 16 Oct 2020 01:20:56 +0100 Subject: [PATCH] Implemented EraseEntry --- z/database.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/z/database.go b/z/database.go index e8f04e0..3a7fc87 100644 --- a/z/database.go +++ b/z/database.go @@ -117,6 +117,31 @@ func (database *Database) FinishEntry(user string, entry Entry) (string, error) return entry.ID, dberr } +func (database *Database) EraseEntry(user string, id string) (error) { + runningEntryId, err := database.GetRunningEntryId(user) + if err != nil { + return err + } + + dberr := database.DB.Update(func(tx *buntdb.Tx) error { + if runningEntryId == id { + _, _, seterr := tx.Set(user + ":status:running", "", nil) + if seterr != nil { + return seterr + } + } + + _, delerr := tx.Delete(user + ":entry:" + id) + if delerr != nil { + return delerr + } + + return nil + }) + + return dberr +} + func (database *Database) GetRunningEntryId(user string) (string, error) { var runningId string = ""