Skip to content

Commit

Permalink
feat: move comment reward display conditionfeat: move comment reward …
Browse files Browse the repository at this point in the history
…display condition
  • Loading branch information
Tanngent2005 committed Apr 10, 2024
1 parent f79ec17 commit 1a88300
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
11 changes: 0 additions & 11 deletions internal/controllers/comments/course_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"coursebench-backend/pkg/database"
"coursebench-backend/pkg/errors"
"coursebench-backend/pkg/models"
"coursebench-backend/pkg/queries"
"strconv"

"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -39,16 +38,6 @@ func CourseGroupComment(c *fiber.Ctx) (err error) {
}
var response []CommentResponse
response = GenerateResponse(comments, uid, likeResult, true, utils.GetIP(c))
currentUser, err := queries.GetUserByID(nil, uid)
if err != nil {
return err
}
if !currentUser.IsAdmin && !currentUser.IsCommunityAdmin {
for i := range response {
// 设置评论的 Reward 字段为 -1,表示不可见
response[i].Reward = -1
}
}
return c.Status(fiber.StatusOK).JSON(models.OKResponse{
Data: response,
Error: false,
Expand Down
7 changes: 7 additions & 0 deletions internal/controllers/comments/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ func GenerateResponse(comments []models.Comment, uid uint, likeResult []CommentL
Reward: v.Reward,
}
// 该评论未设置匿名,或者是自己的评论,则显示用户信息
currentUser, err := queries.GetUserByID(nil, uid)
if err != nil {
c.Reward = -2
}
if !currentUser.IsAdmin && !currentUser.IsCommunityAdmin {
c.Reward = -1
}
if !anonymous || v.User.ID == uid {
t, _ := queries.GetProfile(nil, v.UserID, uid)
c.User = &t
Expand Down

0 comments on commit 1a88300

Please sign in to comment.