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
|
2024-11-01 21:54:11 +01:00
|
|
|
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
|
|
|
|
}
|