42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package entities
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type PeriodType string
|
|
|
|
const (
|
|
PeriodTypeDaily PeriodType = "DAILY"
|
|
PeriodTypeWeekly PeriodType = "WEEKLY"
|
|
PeriodTypeMonthly PeriodType = "MONTHLY"
|
|
PeriodTypeTotal PeriodType = "TOTAL"
|
|
)
|
|
|
|
type OmsetTracker struct {
|
|
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
|
PeriodType PeriodType `gorm:"type:varchar(20);not null" json:"period_type" validate:"required,oneof=DAILY WEEKLY MONTHLY TOTAL"`
|
|
PeriodStart time.Time `gorm:"type:date;not null" json:"period_start" validate:"required"`
|
|
PeriodEnd time.Time `gorm:"type:date;not null" json:"period_end" validate:"required"`
|
|
Total int64 `gorm:"not null;default:0" json:"total" validate:"min=0"`
|
|
GameID *uuid.UUID `gorm:"type:uuid" json:"game_id,omitempty"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
|
|
Game *Game `gorm:"foreignKey:GameID" json:"game,omitempty"`
|
|
}
|
|
|
|
func (ot *OmsetTracker) BeforeCreate(tx *gorm.DB) error {
|
|
if ot.ID == uuid.Nil {
|
|
ot.ID = uuid.New()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (OmsetTracker) TableName() string {
|
|
return "omset_tracker"
|
|
}
|