Implement Journal read/write
This commit is contained in:
@ -5,8 +5,10 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
|
||||
"github.com/moustachioed/dash/backend/database/models"
|
||||
)
|
||||
@ -38,10 +40,18 @@ func (db *PgDatabase) migrate() {
|
||||
db.Db.AutoMigrate(&models.Journal{})
|
||||
}
|
||||
|
||||
func (db *PgDatabase) WriteJournalEntry(dbmodel models.Journal) error {
|
||||
func (db *PgDatabase) WriteJournalEntry(entry models.Journal) error {
|
||||
err := db.Db.Clauses(clause.OnConflict{UpdateAll: true}).Create(&entry).Error
|
||||
if err != nil {
|
||||
log.Print("Error writing journal entry to database.")
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *PgDatabase) GetJournalEntryForDate(date time.Time) (models.Journal, error) {
|
||||
return models.Journal{}, nil
|
||||
entry := models.Journal{Date: datatypes.Date(date)}
|
||||
db.Db.First(&entry)
|
||||
return entry, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user