modified: serv_nginx/api_bb/internal/database/migrate.go
new file: serv_nginx/api_bb/internal/handlers/event_handler.go new file: serv_nginx/api_bb/internal/handlers/event_registration_handler.go modified: serv_nginx/api_bb/internal/handlers/handlers.go modified: serv_nginx/api_bb/internal/models/event.go modified: serv_nginx/api_bb/internal/routes/routes.go new file: serv_nginx/api_bb/internal/service/event_registration_service.go new file: serv_nginx/api_bb/internal/service/event_service.go new file: serv_nginx/api_bb/pkg/middleware/admin_middleware.go add admin middleware, add event and eventRegistration handlers, routes, services, EndPoints
This commit is contained in:
@@ -3,8 +3,6 @@ package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type EventType string
|
||||
@@ -17,85 +15,35 @@ const (
|
||||
)
|
||||
|
||||
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"`
|
||||
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 `json:"registrations,omitempty" gorm:"foreignKey:EventID"`
|
||||
Registrations []EventRegistration `gorm:"foreignKey:EventID" json:"registrations,omitempty"`
|
||||
}
|
||||
|
||||
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"`
|
||||
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"`
|
||||
|
||||
// Связи
|
||||
Event Event `json:"event,omitempty" gorm:"foreignKey:EventID"`
|
||||
User User `json:"user,omitempty" gorm:"foreignKey:UserID"`
|
||||
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
||||
Event *Event `gorm:"foreignKey:EventID" json:"event,omitempty"`
|
||||
}
|
||||
|
||||
// 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"`
|
||||
}
|
||||
Reference in New Issue
Block a user