fin-check-api/db/item_price.go

29 lines
432 B
Go
Raw Normal View History

2024-08-01 23:02:55 +02:00
package db
import (
"errors"
"time"
"gorm.io/gorm"
)
type ItemPrice struct {
gorm.Model
ItemID uint
Item *Item
Price uint64
ValidFrom time.Time
IsValid bool `gorm:"default:true"`
}
var (
ERROR_ITEMPRICE_VALID_FROM_ERR = errors.New("ValidFrom shall be initiated when created")
)
func (i *ItemPrice) BeforeCreate(tx *gorm.DB) error {
if i.ValidFrom.IsZero() {
i.ValidFrom = time.Now()
}
return nil
}