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:
@@ -48,6 +48,7 @@ func autoMigrate(db *gorm.DB) error {
|
||||
&models.VoteBreakdown{},
|
||||
&models.Rating{},
|
||||
&models.Feedback{},
|
||||
&models.Comment{},
|
||||
}
|
||||
|
||||
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
|
||||
Score int `json:"score"`
|
||||
|
||||
// Связь с комментариями
|
||||
Comments []Comment `gorm:"foreignKey:FeedbackID" json:"comments,omitempty"`
|
||||
CommentCount int `gorm:"default:0" json:"comment_count"`
|
||||
|
||||
// Основная информация
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user