feat: 互动处理
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user