feat: 相关业务的调用

This commit is contained in:
Leon
2025-12-30 01:26:38 +08:00
parent 116724a845
commit 4a91452fc3
2 changed files with 31 additions and 5 deletions

View File

@@ -77,3 +77,21 @@ func (vr *VideoRepository) UpdatePopularity(ctx context.Context, id uint, change
}
return nil
}
func (vr *VideoRepository) ChangeLikesCount(ctx context.Context, id uint, change int64) error {
if err := vr.db.WithContext(ctx).Model(&Video{}).
Where("id = ?", id).
UpdateColumn("likes_count", gorm.Expr("GREATEST(likes_count + ?, 0)", change)).Error; err != nil {
return err
}
return nil
}
func (vr *VideoRepository) ChangePopularity(ctx context.Context, id uint, change int64) error {
if err := vr.db.WithContext(ctx).Model(&Video{}).
Where("id = ?", id).
UpdateColumn("popularity", gorm.Expr("GREATEST(popularity + ?, 0)", change)).Error; err != nil {
return err
}
return nil
}