refactor(notification): 通知实体抽成独立包

`video` 与 `worker` 各有一份 `notifications` 表的实体。
两份定义会漂移,所以合并到 `internal/notification`。
新增 `entity.go` 保存唯一一份列标签。

`worker`、`ssehub`、`comment_repo`、`db` 与两个集成测试改为引用新包。
`db` 包不再 import `worker`。
去重键仍是 `*string`,因此 NULL 才能共存。

验证:go test -count=1 ./... 全绿;集成测试三包全绿。
This commit is contained in:
2026-10-30 23:48:43 +08:00
parent 07f3166ab7
commit 151faf25fa
9 changed files with 87 additions and 83 deletions

View File

@@ -4,6 +4,8 @@ import (
"context"
"time"
"feedsystem_video_go/internal/notification"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
@@ -119,17 +121,17 @@ func (r *CommentRepository) GetByID(ctx context.Context, id uint) (*Comment, err
// CreateMentions 幂等写入提及通知:DedupeKey 相同则静默跳过。
//
// 显式写 CreatedAt 而不依赖 autoCreateTime:这条路径写的是"列投影"而不是
// worker 包的实体,autoCreateTime 只在 GORM 认为字段是零值时才生效——一旦
// 有人在调用前给 CreatedAt 赋了零值以外的值,两种来源就会打架(P2-16 ①)。
// 显式写 CreatedAt 而不依赖 autoCreateTime:这一批行共享同一个时间戳,便于
// 按"同一次评论"检索;autoCreateTime 只在字段为零值时才生效,依赖它会让
// 同一批写入拿到毫秒级不同的时间(P2-16 ①)。
func (r *CommentRepository) CreateMentions(ctx context.Context, mentions []Mention) error {
if len(mentions) == 0 {
return nil
}
now := time.Now()
rows := make([]NotificationRow, 0, len(mentions))
rows := make([]notification.Notification, 0, len(mentions))
for _, m := range mentions {
rows = append(rows, NotificationRow{
rows = append(rows, notification.Notification{
RecipientID: m.RecipientID,
SenderID: m.SenderID,
Type: "mention",