modified: main_dc/yalarba/api_yal/internal/database/psql_db.go

new file:   main_dc/yalarba/api_yal/internal/models/comment.go
	modified:   main_dc/yalarba/api_yal/internal/models/feedback.go
add comment into models
add comment into feedback
add comment into autoMigrate psql_db.go
This commit is contained in:
2026-02-22 14:04:55 +05:00
parent 7ae2acfd8c
commit c0734f50e8
3 changed files with 34 additions and 0 deletions
@@ -48,6 +48,7 @@ func autoMigrate(db *gorm.DB) error {
&models.VoteBreakdown{}, &models.VoteBreakdown{},
&models.Rating{}, &models.Rating{},
&models.Feedback{}, &models.Feedback{},
&models.Comment{},
} }
for _, model := range models { for _, model := range models {
@@ -0,0 +1,29 @@
package models
import ()
// Comment представляет комментарий к отзыву (Feedback)
type Comment struct {
/*ID, CreatedAt, UpdatedAt, DeletedAt (Update's history)*/
Base Base `gorm:"embedded"`
// Автор комментария
AuthorID uint `gorm:"not null;index" json:"author_id"`
Author Account `gorm:"foreignKey:AuthorID;references:ID" json:"author,omitempty"`
// Отзыв, к которому оставлен комментарий
FeedbackID uint `gorm:"not null;index" json:"feedback_id"`
Feedback Feedback `gorm:"foreignKey:FeedbackID;references:ID" json:"feedback,omitempty"`
// Содержание комментария
Text string `gorm:"not null" json:"text"`
// Для поддержки вложенных комментариев (ответы на комментарии)
ParentID *uint `gorm:"index" json:"parent_id,omitempty"` // NULL для корневых комментариев
Parent *Comment `gorm:"foreignKey:ParentID;references:ID" json:"parent,omitempty"`
Replies []Comment `gorm:"foreignKey:ParentID;references:ID" json:"replies,omitempty"`
// Статус
IsEdited bool `gorm:"default:false" json:"is_edited"`
IsVerified bool `gorm:"default:false" json:"is_verified"` // если нужна модерация
}
@@ -20,6 +20,10 @@ type Feedback struct {
// 1 - 5 // 1 - 5
Score int `json:"score"` Score int `json:"score"`
// Связь с комментариями
Comments []Comment `gorm:"foreignKey:FeedbackID" json:"comments,omitempty"`
CommentCount int `gorm:"default:0" json:"comment_count"`
// Основная информация // Основная информация
Text string `json:"text"` Text string `json:"text"`
} }