Implemented EraseEntry

This commit is contained in:
マリウス 2020-10-16 01:20:56 +01:00
parent 968f3beee3
commit 45fe5093d0
No known key found for this signature in database
GPG key ID: C228EF0A530AF06F

View file

@ -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 = ""