feat: 互动处理

This commit is contained in:
Blizzard
2026-03-05 10:30:29 +08:00
parent 172e5f791f
commit 74b252550b
11 changed files with 846 additions and 790 deletions
+14
View File
@@ -11,6 +11,8 @@ import (
type InteractionService struct{}
var InteractionServiceApp = new(InteractionService)
// AddHistory 添加收听历史
func (s *InteractionService) AddHistory(userId string, req radioReq.AddHistory) error {
// 先查找是否已存在记录
@@ -174,3 +176,15 @@ func (s *InteractionService) GetCommentList(programId string, info radioReq.GetC
err = db.Offset(offset).Limit(info.PageSize).Order("created_at DESC").Find(&list).Error
return list, total, err
}
func (s *InteractionService) DeleteHistory(userId, programId string) error {
return global.DB.Where("user_id = ? AND program_id = ?", userId, programId).Delete(&radio.RadioHistory{}).Error
}
func (s *InteractionService) DeleteAllHistory(userId string) error {
return global.DB.Where("user_id = ?", userId).Delete(&radio.RadioHistory{}).Error
}
func (s *InteractionService) RemoveAllFavorite(userId string) error {
return global.DB.Where("user_id = ?", userId).Delete(&radio.RadioFavorite{}).Error
}
+12 -1
View File
@@ -37,9 +37,20 @@ func (s *ProgramService) GetProgramList(info radioReq.GetProgramList) ([]radio.R
}
// GetProgramById 获取节目详情
func (s *ProgramService) GetProgramById(id string) (*radio.RadioProgram, error) {
func (s *ProgramService) GetProgramById(id, userId string) (*radio.RadioProgram, error) {
var program radio.RadioProgram
err := global.DB.Where("id = ?", id).Preload("Audio").First(&program).Error
program.HasLiked = 0
program.HasFavorite = 0
liked, err := InteractionServiceApp.IsLiked(userId, id)
if liked {
program.HasLiked = 1
}
favorite, err := InteractionServiceApp.IsFavorited(userId, id)
if favorite {
program.HasFavorite = 1
}
return &program, err
}