Skip to content

Commit

Permalink
Move comment reward display condition from controllers/comments/cours…
Browse files Browse the repository at this point in the history
…e_group into controllers/comments.GenerateResponse.
  • Loading branch information
Tanngent2005 committed Apr 9, 2024
1 parent 6f1854c commit 18b44c5
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 18b44c5

Please sign in to comment.