feat: 添加了删除视频功能并添加了一些边界检查

This commit is contained in:
Leon
2025-12-16 18:51:17 +08:00
parent 7883a7427d
commit ef47d5e2de
4 changed files with 68 additions and 18 deletions

View File

@@ -29,6 +29,20 @@ func (vs *VideoService) Publish(ctx context.Context, video *Video) error {
return nil
}
func (vs *VideoService) Delete(ctx context.Context, id uint, authorID uint) error {
video, err := vs.repo.GetByID(ctx, id)
if err != nil {
return err
}
if video.AuthorID != authorID {
return errors.New("unauthorized")
}
if err := vs.repo.DeleteVideo(ctx, id); err != nil {
return err
}
return nil
}
func (vs *VideoService) ListByAuthorID(ctx context.Context, authorID uint) ([]Video, error) {
videos, err := vs.repo.ListByAuthorID(ctx, int64(authorID))
if err != nil {