2024-07-04 22:29:32 +02:00
|
|
|
package flightlesssomething
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/dustin/go-humanize"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type User struct {
|
|
|
|
gorm.Model
|
|
|
|
DiscordID string
|
|
|
|
Username string
|
|
|
|
|
|
|
|
Benchmarks []Benchmark `gorm:"constraint:OnDelete:CASCADE;"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Benchmark struct {
|
|
|
|
gorm.Model
|
2024-07-11 18:33:15 +02:00
|
|
|
UserID uint
|
|
|
|
Title string
|
|
|
|
Description string
|
2024-07-04 22:29:32 +02:00
|
|
|
|
|
|
|
CreatedAtHumanized string `gorm:"-"` // Human readable "X h/m/s ago" version of CreatedAt (filled automatically)
|
|
|
|
|
|
|
|
User User `gorm:"foreignKey:UserID;"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// AfterFind is a GORM hook that is called after a record is found
|
|
|
|
func (b *Benchmark) AfterFind(tx *gorm.DB) (err error) {
|
|
|
|
b.CreatedAtHumanized = humanize.Time(b.CreatedAt)
|
|
|
|
return nil
|
|
|
|
}
|