huangguangrong hace 7 meses
padre
commit
af51137f56

+ 1 - 1
etc/slowwild.yaml

@@ -14,6 +14,6 @@ DB:
   DataSource: root:easy-chat@tcp(121.11.99.220:13306)/slow_wild?charset=utf8mb4&parseTime=True&loc=Local
 
 RedisConf:
-  Host: 127.0.0.1:6379
+  Host: 121.11.99.220:16379
   Password: ""
   DB: 0

+ 5 - 3
internal/logic/getpostlogic.go

@@ -2,6 +2,7 @@ package logic
 
 import (
 	"context"
+	"errors"
 	"slowwild/internal/constants"
 	"slowwild/internal/errorx"
 	"slowwild/internal/svc"
@@ -9,6 +10,7 @@ import (
 	"strings"
 
 	"git.banshen.xyz/huangguangrong/slow_wild_protobuff/slowwild/slowwildserver"
+	"gorm.io/gorm"
 
 	"github.com/spf13/cast"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -70,7 +72,7 @@ func (l *GetPostLogic) GetPost(in *slowwildserver.GetPostReq) (*slowwildserver.G
 		}
 
 		tags, err := l.svcCtx.TagModel.FindByIds(l.ctx, tagIds)
-		if err != nil {
+		if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
 			l.Logger.Errorf("获取话题信息失败: %v", err)
 			return nil, errorx.ErrPostQueryFailed
 		}
@@ -86,13 +88,13 @@ func (l *GetPostLogic) GetPost(in *slowwildserver.GetPostReq) (*slowwildserver.G
 	// 获取用户交互状态
 	if userId > 0 {
 		isLiked, err = l.svcCtx.UserModel.IsPostLikedByUser(l.ctx, userId, post.ID)
-		if err != nil {
+		if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
 			l.Logger.Errorf("查询用户点赞状态失败: %v", err)
 			return nil, errorx.ErrPostQueryFailed
 		}
 
 		isCollected, err = l.svcCtx.UserModel.IsPostCollectedByUser(l.ctx, userId, post.ID)
-		if err != nil {
+		if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
 			l.Logger.Errorf("查询用户收藏状态失败: %v", err)
 			return nil, errorx.ErrPostQueryFailed
 		}

+ 2 - 2
internal/model/post_model.go

@@ -201,7 +201,7 @@ func (m *PostModel) IsPostLikedByUser(ctx context.Context, userId, postId int64)
 	var count int64
 	err = m.conn.WithContext(ctx).
 		Model(&PostAction{}).
-		Where("user_id = ? AND post_id = ? and type = 0", userId, postId).
+		Where("user_id = ? AND post_id = ? and action_type = 0", userId, postId).
 		Count(&count).Error
 	if err != nil {
 		return false, err
@@ -223,7 +223,7 @@ func (m *PostModel) IsPostCollectedByUser(ctx context.Context, userId, postId in
 	var count int64
 	err = m.conn.WithContext(ctx).
 		Model(&PostAction{}).
-		Where("user_id = ? AND post_id = ? and type = 1", userId, postId).
+		Where("user_id = ? AND post_id = ? and action_type = 1", userId, postId).
 		Count(&count).Error
 	if err != nil {
 		return false, err

+ 2 - 2
internal/model/user_model.go

@@ -176,7 +176,7 @@ func (m *UserModel) IsPostLikedByUser(ctx context.Context, userId, postId int64)
 	var count int64
 	err := m.conn.WithContext(ctx).
 		Model(&PostAction{}).
-		Where("user_id = ? AND post_id = ? and type = 0", userId, postId).
+		Where("user_id = ? AND post_id = ? and action_type = 0", userId, postId).
 		Count(&count).Error
 	return count > 0, err
 }
@@ -186,7 +186,7 @@ func (m *UserModel) IsPostCollectedByUser(ctx context.Context, userId, postId in
 	var count int64
 	err := m.conn.WithContext(ctx).
 		Model(&PostAction{}).
-		Where("user_id = ? AND post_id = ? and type = 1", userId, postId).
+		Where("user_id = ? AND post_id = ? and action_type = 1", userId, postId).
 		Count(&count).Error
 	return count > 0, err
 }