Make interfaces abstract
This commit is contained in:
@ -2,11 +2,10 @@ package database
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/moustachioed/dash/backend/database/models"
|
||||
// "github.com/moustachioed/dash/backend/database/models"
|
||||
)
|
||||
|
||||
type Database interface {
|
||||
WriteJournalEntry(models.Journal) error
|
||||
GetJournalEntryForDate(time.Time) (models.Journal, error)
|
||||
WriteJournalEntry(interface{}) error
|
||||
GetJournalEntryForDate(time.Time) (interface{}, error)
|
||||
}
|
||||
|
||||
@ -40,8 +40,9 @@ func (db *PgDatabase) migrate() {
|
||||
db.Db.AutoMigrate(&models.Journal{})
|
||||
}
|
||||
|
||||
func (db *PgDatabase) WriteJournalEntry(entry models.Journal) error {
|
||||
err := db.Db.Clauses(clause.OnConflict{UpdateAll: true}).Create(&entry).Error
|
||||
func (db *PgDatabase) WriteJournalEntry(entry interface{}) error {
|
||||
journal := entry.(models.Journal)
|
||||
err := db.Db.Clauses(clause.OnConflict{UpdateAll: true}).Create(&journal).Error
|
||||
if err != nil {
|
||||
log.Print("Error writing journal entry to database.")
|
||||
return err
|
||||
@ -50,8 +51,9 @@ func (db *PgDatabase) WriteJournalEntry(entry models.Journal) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *PgDatabase) GetJournalEntryForDate(date time.Time) (models.Journal, error) {
|
||||
func (db *PgDatabase) GetJournalEntryForDate(date time.Time) (interface{}, error) {
|
||||
entry := models.Journal{Date: datatypes.Date(date)}
|
||||
db.Db.First(&entry)
|
||||
|
||||
return entry, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user