package models import ( "time" "gorm.io/gorm" ) type NewsCategory string const ( NewsCategoryEvents NewsCategory = "events" NewsCategoryTraining NewsCategory = "training" NewsCategoryAchievements NewsCategory = "achievements" NewsCategoryCommunity NewsCategory = "community" ) type News struct { ID uint `json:"id" gorm:"primarykey"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"` Title string `json:"title" gorm:"size:255;not null"` Excerpt string `json:"excerpt" gorm:"size:500;not null"` Content string `json:"content" gorm:"type:text;not null"` Image string `json:"image" gorm:"size:255"` Category NewsCategory `json:"category" gorm:"type:varchar(20);not null"` Views int `json:"views" gorm:"default:0"` // Связи AuthorID uint `json:"author_id" gorm:"not null"` Author User `json:"author" gorm:"foreignKey:AuthorID"` Comments []Comment `json:"comments,omitempty" gorm:"foreignKey:NewsID"` } type Comment struct { ID uint `json:"id" gorm:"primarykey"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` Content string `json:"content" gorm:"type:text;not null"` // Связи NewsID uint `json:"news_id" gorm:"not null"` AuthorID uint `json:"author_id" gorm:"not null"` Author User `json:"author" gorm:"foreignKey:AuthorID"` } // DTO для создания новости type CreateNewsRequest struct { Title string `json:"title" validate:"required,min=5,max=255"` Excerpt string `json:"excerpt" validate:"required,min=10,max=500"` Content string `json:"content" validate:"required,min=50"` Image string `json:"image"` Category NewsCategory `json:"category" validate:"required,oneof=events training achievements community"` } // DTO для обновления новости type UpdateNewsRequest struct { Title string `json:"title" validate:"omitempty,min=5,max=255"` Excerpt string `json:"excerpt" validate:"omitempty,min=10,max=500"` Content string `json:"content" validate:"omitempty,min=50"` Image string `json:"image"` Category NewsCategory `json:"category" validate:"omitempty,oneof=events training achievements community"` } // DTO для ответа с новостью type NewsResponse struct { ID uint `json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` Title string `json:"title"` Excerpt string `json:"excerpt"` Content string `json:"content"` Image string `json:"image"` Category NewsCategory `json:"category"` Views int `json:"views"` Author AuthorInfo `json:"author"` Comments int `json:"comments_count"` } type AuthorInfo struct { ID uint `json:"id"` FirstName string `json:"first_name"` LastName string `json:"last_name"` Email string `json:"email,omitempty"` } // DTO для комментария type CreateCommentRequest struct { Content string `json:"content" validate:"required,min=1,max=1000"` } type CommentResponse struct { ID uint `json:"id"` CreatedAt time.Time `json:"created_at"` Content string `json:"content"` Author AuthorInfo `json:"author"` }