50 lines
2.2 KiB
Go
50 lines
2.2 KiB
Go
// models/event.go
|
|
package models
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type EventType string
|
|
|
|
const (
|
|
EventTypeRace EventType = "race"
|
|
EventTypeTraining EventType = "training"
|
|
EventTypeSocial EventType = "social"
|
|
EventTypeWorkshop EventType = "workshop"
|
|
)
|
|
|
|
type Event struct {
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
|
Title string `gorm:"size:255;not null" json:"title" validate:"required,min=5,max=255"`
|
|
Description string `gorm:"type:text;not null" json:"description" validate:"required,min=10"`
|
|
Date time.Time `gorm:"not null" json:"date" validate:"required"`
|
|
Location string `gorm:"size:255;not null" json:"location" validate:"required,max=255"`
|
|
Type EventType `gorm:"size:50;not null" json:"type" validate:"required,oneof=race training social workshop"`
|
|
Distance string `gorm:"size:50" json:"distance" validate:"max=50"`
|
|
ParticipantsCount int `gorm:"default:0" json:"participants_count"`
|
|
MaxParticipants int `gorm:"default:0" json:"max_participants" validate:"min=0"`
|
|
RegistrationOpen bool `gorm:"default:true" json:"registration_open"`
|
|
Image string `gorm:"size:500" json:"image" validate:"max=500"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
|
|
// Связи
|
|
Registrations []EventRegistration `gorm:"foreignKey:EventID" json:"registrations,omitempty"`
|
|
}
|
|
|
|
type EventRegistration struct {
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
|
UserID uint `gorm:"not null" json:"user_id"`
|
|
EventID uint `gorm:"not null" json:"event_id"`
|
|
Status string `gorm:"size:50;default:pending" json:"status" validate:"oneof=pending confirmed cancelled completed"`
|
|
Notes string `gorm:"type:text" json:"notes" validate:"max=500"`
|
|
ResultTime string `gorm:"size:20" json:"result_time" validate:"max=20"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
|
|
// Связи
|
|
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
|
Event *Event `gorm:"foreignKey:EventID" json:"event,omitempty"`
|
|
}
|