fin-check-api/db/item_price.go

29 lines
415 B
Go
Raw Permalink 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
ValidTo time.Time
2024-08-01 23:02:55 +02:00
}
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
}