Files
tp/serv_nginx/api_bb/internal/models/event.go
T
valitovgaziz b19ce8fdfe modified: README.md
modified:   serv_nginx/api_bb/go.mod
	modified:   serv_nginx/api_bb/go.sum
	new file:   serv_nginx/api_bb/internal/models/achievement.go
	new file:   serv_nginx/api_bb/internal/models/common.go
	new file:   serv_nginx/api_bb/internal/models/event.go
	new file:   serv_nginx/api_bb/internal/models/gallery.go
	modified:   serv_nginx/api_bb/internal/models/news.go
	new file:   serv_nginx/api_bb/internal/models/personal_best.go
	new file:   serv_nginx/api_bb/internal/models/training_plan.go
	modified:   serv_nginx/api_bb/internal/models/user.go
	new file:   serv_nginx/api_bb/internal/models/user_stats.go
	modified:   serv_nginx/api_bb/internal/models/workout.go
	modified:   serv_nginx/bbvue/src/components/NavigationMenu.vue
	new file:   serv_nginx/bbvue/src/components/writeLogo.vue
add satructs for begushiybashkir.ru site
2025-10-17 05:09:53 +05:00

101 lines
3.7 KiB
Go

// models/event.go
package models
import (
"time"
"gorm.io/gorm"
)
type EventType string
const (
EventTypeRace EventType = "race"
EventTypeTraining EventType = "training"
EventTypeSocial EventType = "social"
EventTypeWorkshop EventType = "workshop"
)
type Event struct {
ID uint `json:"id" gorm:"primaryKey"`
Title string `json:"title" gorm:"size:255;not null"`
Description string `json:"description" gorm:"type:text;not null"`
Date time.Time `json:"date" gorm:"not null;index"`
Location string `json:"location" gorm:"size:255;not null"`
Type EventType `json:"type" gorm:"type:varchar(20);not null"`
Distance string `json:"distance" gorm:"size:50"` // Дистанция забега
ParticipantsCount int `json:"participants_count" gorm:"default:0"` // Количество участников
MaxParticipants int `json:"max_participants" gorm:"default:0"` // Максимальное количество участников
RegistrationOpen bool `json:"registration_open" gorm:"default:true"` // Открыта ли регистрация
Image string `json:"image" gorm:"size:500"` // Изображение события
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Связи
Registrations []EventRegistration `json:"registrations,omitempty" gorm:"foreignKey:EventID"`
}
type EventRegistration struct {
ID uint `json:"id" gorm:"primaryKey"`
EventID uint `json:"event_id" gorm:"not null;index"`
UserID uint `json:"user_id" gorm:"not null;index"`
Status string `json:"status" gorm:"size:20;default:pending"` // pending, confirmed, cancelled, completed
ResultTime *string `json:"result_time" gorm:"size:20"` // Результат забега
BibNumber *string `json:"bib_number" gorm:"size:10"` // Стартовый номер
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Связи
Event Event `json:"event,omitempty" gorm:"foreignKey:EventID"`
User User `json:"user,omitempty" gorm:"foreignKey:UserID"`
}
// BeforeCreate hooks
func (e *Event) BeforeCreate(tx *gorm.DB) error {
if e.CreatedAt.IsZero() {
e.CreatedAt = time.Now()
}
if e.UpdatedAt.IsZero() {
e.UpdatedAt = time.Now()
}
return nil
}
func (er *EventRegistration) BeforeCreate(tx *gorm.DB) error {
if er.CreatedAt.IsZero() {
er.CreatedAt = time.Now()
}
if er.UpdatedAt.IsZero() {
er.UpdatedAt = time.Now()
}
return nil
}
// BeforeUpdate hooks
func (e *Event) BeforeUpdate(tx *gorm.DB) error {
e.UpdatedAt = time.Now()
return nil
}
func (er *EventRegistration) BeforeUpdate(tx *gorm.DB) error {
er.UpdatedAt = time.Now()
return nil
}
// DTO для создания события
type EventCreateRequest struct {
Title string `json:"title" validate:"required,min=5,max=255"`
Description string `json:"description" validate:"required,min=10"`
Date time.Time `json:"date" validate:"required"`
Location string `json:"location" validate:"required,max=255"`
Type EventType `json:"type" validate:"required,oneof=race training social workshop"`
Distance string `json:"distance" validate:"max=50"`
MaxParticipants int `json:"max_participants" validate:"min=0"`
RegistrationOpen bool `json:"registration_open"`
Image string `json:"image" validate:"max=500"`
}
// DTO для регистрации на событие
type EventRegistrationRequest struct {
EventID uint `json:"event_id" validate:"required"`
}