Move WissKI Parts to new ingredients system

This commit is contained in:
Tom Wiesing 2022-10-18 10:44:39 +02:00
parent b5b1ce2340
commit 42b8cbd865
No known key found for this signature in database
83 changed files with 1016 additions and 646 deletions

View file

@ -0,0 +1,43 @@
package bookkeeping
import (
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
)
// Bookkeeping provides instance bookkeeping
type Bookkeeping struct {
ingredient.Base
}
// Save saves this instance in the bookkeeping table
func (bk *Bookkeeping) Save() error {
sdb, err := bk.Malt.SQL.QueryTable(false, models.InstanceTable)
if err != nil {
return err
}
// it has never been created => we need to create it in the database
if bk.Instance.Created.IsZero() {
return sdb.Create(&bk.Instance).Error
}
// Update based on the primary key!
return sdb.Where("pk = ?", bk.Instance.Pk).Updates(&bk.Instance).Error
}
// Delete deletes this instance from the bookkeeping table
func (bk *Bookkeeping) Delete() error {
sdb, err := bk.Malt.SQL.QueryTable(false, models.InstanceTable)
if err != nil {
return err
}
// doesn't exist => nothing to delete
if bk.Instance.Created.IsZero() {
return nil
}
// delete it directly
return sdb.Delete(&bk.Instance).Error
}