6bb475acb2
modified: begushiybashkir/bbvue/src/views/Login.vue new file: begushiybashkir/bbvue/src/views/Logout.vue modified: begushiybashkir/bbvue/src/views/News.vue modified: begushiybashkir/bbvue/src/views/Profile.vue modified: serv_nginx/api_bb/cmd/main.go modified: serv_nginx/api_bb/go.mod modified: serv_nginx/api_bb/go.sum new file: serv_nginx/api_bb/internal/app/app.go new file: serv_nginx/api_bb/internal/database/database.go new file: serv_nginx/api_bb/internal/database/migrate.go new file: serv_nginx/api_bb/internal/handlers/news_handler.go new file: serv_nginx/api_bb/internal/models/news.go new file: serv_nginx/api_bb/internal/repository/comment_repository.go new file: serv_nginx/api_bb/internal/repository/news_repository.go modified: serv_nginx/api_bb/internal/routes/routes.go new file: serv_nginx/api_bb/internal/service/news_service.go modified: serv_nginx/api_bb/pkg/utils/utils.go save router paths to login logout profile from upsunction commit
100 lines
3.6 KiB
Go
100 lines
3.6 KiB
Go
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"`
|
|
} |