b19ce8fdfe
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
74 lines
2.5 KiB
Go
74 lines
2.5 KiB
Go
// models/gallery.go
|
|
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type GalleryCategory string
|
|
|
|
const (
|
|
GalleryCategoryTraining GalleryCategory = "training"
|
|
GalleryCategoryEvents GalleryCategory = "events"
|
|
GalleryCategoryCommunity GalleryCategory = "community"
|
|
GalleryCategoryAchievements GalleryCategory = "achievements"
|
|
)
|
|
|
|
type Gallery struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
Title string `json:"title" gorm:"size:255;not null"`
|
|
Description string `json:"description" gorm:"type:text"`
|
|
ImagePath string `json:"image_path" gorm:"size:500;not null"` // Путь к изображению
|
|
Category GalleryCategory `json:"category" gorm:"type:varchar(20);not null"`
|
|
AuthorID uint `json:"author_id" gorm:"not null;index"`
|
|
EventDate *time.Time `json:"event_date"` // Дата события на фото
|
|
Views int `json:"views" gorm:"default:0"`
|
|
Likes int `json:"likes" gorm:"default:0"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
// Связи
|
|
Author User `json:"author,omitempty" gorm:"foreignKey:AuthorID"`
|
|
}
|
|
|
|
// BeforeCreate hook
|
|
func (g *Gallery) BeforeCreate(tx *gorm.DB) error {
|
|
if g.CreatedAt.IsZero() {
|
|
g.CreatedAt = time.Now()
|
|
}
|
|
if g.UpdatedAt.IsZero() {
|
|
g.UpdatedAt = time.Now()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// BeforeUpdate hook
|
|
func (g *Gallery) BeforeUpdate(tx *gorm.DB) error {
|
|
g.UpdatedAt = time.Now()
|
|
return nil
|
|
}
|
|
|
|
// DTO для создания записи в галерее
|
|
type GalleryCreateRequest struct {
|
|
Title string `json:"title" validate:"required,min=5,max=255"`
|
|
Description string `json:"description" validate:"max=1000"`
|
|
ImagePath string `json:"image_path" validate:"required,max=500"`
|
|
Category GalleryCategory `json:"category" validate:"required,oneof=training events community achievements"`
|
|
EventDate *time.Time `json:"event_date"`
|
|
}
|
|
|
|
// DTO для ответа с галереей
|
|
type GalleryResponse struct {
|
|
ID uint `json:"id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
ImagePath string `json:"image_path"`
|
|
Category GalleryCategory `json:"category"`
|
|
EventDate *time.Time `json:"event_date"`
|
|
Views int `json:"views"`
|
|
Likes int `json:"likes"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
Author AuthorInfo `json:"author"`
|
|
} |