Skip to content

Commit

Permalink
修改 bug 更改comment接口redis逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
Chiba-little-black-cat committed Aug 29, 2023
1 parent 8728fb7 commit 95d1710
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/favorite/dao/favorite.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ func (f *FavoriteDao) GetFavoriteListByUserId(uid int64) (favorites []*model.Fav
return
}

func (f *FavoriteDao) GetIsFavoriteByUserIdAndVid(uid int64, vid int64) (isFavorite bool, err error) {
var count int64
err = f.Model(&model.Favorite{}).Where("user_id = ?", uid).Where("video_id = ?", vid).Count(&count).Error
if err != nil {
return false, err
}
if count > 0 {
return true, nil
}
return false, nil
}

func (f *FavoriteDao) GetFollowCount(uid int) (count int64, err error) {
err = f.Model(&model.Follow{}).Where("followed_user_id = ?", uid).Count(&count).Error
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions app/favorite/service/favorite.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ func GetFavoriteSrv() *FavoriteSrv {
func (c FavoriteSrv) FavoriteAction(ctx context.Context, req *favoritePb.FavoriteActionRequest, res *favoritePb.FavoriteActionResponse) error {
actionType := req.ActionType
vid := req.VideoId
uid, _ := util.GetUserIdFromToken(req.Token)

body, _ := json.Marshal(&req)

// 点赞
if actionType == 1 {
// 不能重复点赞
isFavorite, _ := dao.NewFavoriteDao(ctx).GetIsFavoriteByUserIdAndVid(int64(uid), vid)
if isFavorite {
FavoriteActionResponseData(res, 1, "重复点赞")
return nil
}

//修改redis
key := fmt.Sprintf("%d", vid)
redisResult, err := dao.RedisClient.Get(ctx, key).Result()
Expand Down

0 comments on commit 95d1710

Please sign in to comment.