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

40 lines
1.2 KiB
Go
Raw Normal View History

package video
import (
"context"
)
// Mention 是一条待写入的提及通知。
type Mention struct {
RecipientID uint
SenderID uint
TargetID uint
Content string
DedupeKey string
}
type CommentStore interface {
// CreateIdempotentWithPopularity 在同一事务内插入评论并给热度加 delta。
// created=false 表示该意图已落库,调用方不得再加热度。
CreateIdempotentWithPopularity(ctx context.Context, c *Comment, delta int64) (created bool, err error)
GetByID(ctx context.Context, id uint) (*Comment, error)
// DeleteWithPopularity 在同一事务内删除评论并向热度 -1。
// 返回被删的行(拿 created_at 落桶);deleted=false 表示空操作。
DeleteWithPopularity(ctx context.Context, id uint) (row *Comment, deleted bool, err error)
GetAllComments(ctx context.Context, videoID uint) ([]Comment, error)
CreateMentions(ctx context.Context, mentions []Mention) error
FindAccountIDs(ctx context.Context, usernames []string) (map[string]uint, error)
}
// nilIfEmpty 供可空唯一列使用:空串会互撞,NULL 才是"没有这个键"。
func nilIfEmpty(s string) *string {
if s == "" {
return nil
}
return &s
}