Files
VLoop/backend/internal/video/comment_entity.go

35 lines
1.3 KiB
Go
Raw Normal View History

2025-12-16 18:51:50 +08:00
package video
import "time"
// Comment 的 (created_at, video_id) 覆盖索引 idx_comments_created_video
// 服务热榜窗口查询与 DB 回退排序:范围扫描走 created_at,video_id 留在
// 索引里避免回表。
2025-12-16 18:51:50 +08:00
type Comment struct {
ID uint `gorm:"primaryKey" json:"id"`
Username string `gorm:"index" json:"username"`
VideoID uint `gorm:"index;index:idx_comments_created_video,priority:2" json:"video_id"`
AuthorID uint `gorm:"index;uniqueIndex:uk_comments_author_key,priority:1" json:"author_id"`
2025-12-16 18:51:50 +08:00
Content string `gorm:"type:text" json:"content"`
CreatedAt time.Time `gorm:"autoCreateTime;index:idx_comments_created_video,priority:1" json:"created_at"`
// IdempotencyKey 必须是 *string:空串会互撞唯一索引,NULL 不会。
IdempotencyKey *string `gorm:"column:idempotency_key;type:varchar(64);uniqueIndex:uk_comments_author_key,priority:2" json:"-"`
2025-12-16 18:51:50 +08:00
}
type PublishCommentRequest struct {
VideoID uint `json:"video_id"`
Content string `json:"content"`
// RequestID 由客户端为一次发送动作生成,重试时复用;为空则服务端生成。
RequestID string `json:"request_id"`
2025-12-16 18:51:50 +08:00
}
type DeleteCommentRequest struct {
CommentID uint `json:"comment_id"`
}
type GetAllCommentsRequest struct {
VideoID uint `json:"video_id"`
}