Skip to content

Commit 1a88300

Browse files
committed
feat: move comment reward display conditionfeat: move comment reward display condition
1 parent f79ec17 commit 1a88300

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

internal/controllers/comments/course_group.go

-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"coursebench-backend/pkg/database"
77
"coursebench-backend/pkg/errors"
88
"coursebench-backend/pkg/models"
9-
"coursebench-backend/pkg/queries"
109
"strconv"
1110

1211
"github.com/gofiber/fiber/v2"
@@ -39,16 +38,6 @@ func CourseGroupComment(c *fiber.Ctx) (err error) {
3938
}
4039
var response []CommentResponse
4140
response = GenerateResponse(comments, uid, likeResult, true, utils.GetIP(c))
42-
currentUser, err := queries.GetUserByID(nil, uid)
43-
if err != nil {
44-
return err
45-
}
46-
if !currentUser.IsAdmin && !currentUser.IsCommunityAdmin {
47-
for i := range response {
48-
// 设置评论的 Reward 字段为 -1,表示不可见
49-
response[i].Reward = -1
50-
}
51-
}
5241
return c.Status(fiber.StatusOK).JSON(models.OKResponse{
5342
Data: response,
5443
Error: false,

internal/controllers/comments/user.go

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ func GenerateResponse(comments []models.Comment, uid uint, likeResult []CommentL
114114
Reward: v.Reward,
115115
}
116116
// 该评论未设置匿名,或者是自己的评论,则显示用户信息
117+
currentUser, err := queries.GetUserByID(nil, uid)
118+
if err != nil {
119+
c.Reward = -2
120+
}
121+
if !currentUser.IsAdmin && !currentUser.IsCommunityAdmin {
122+
c.Reward = -1
123+
}
117124
if !anonymous || v.User.ID == uid {
118125
t, _ := queries.GetProfile(nil, v.UserID, uid)
119126
c.User = &t

0 commit comments

Comments
 (0)