Skip to content

Commit

Permalink
Avoid duplicate code in users/profile, comments/course_group
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanngent2005 committed Apr 9, 2024
1 parent 5c18730 commit 88ce7f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
20 changes: 9 additions & 11 deletions internal/controllers/comments/course_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ func CourseGroupComment(c *fiber.Ctx) (err error) {
if err != nil {
return err
}
if currentUser.IsAdmin || currentUser.IsCommunityAdmin {
return c.Status(fiber.StatusOK).JSON(models.OKResponse{
Data: response,
Error: false,
})
} else {
response.Reward = -1
return c.Status(fiber.StatusOK).JSON(models.OKResponse{
Data: response,
Error: false,
})
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,
})
}
15 changes: 5 additions & 10 deletions internal/controllers/users/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,11 @@ func Profile(c *fiber.Ctx) error {
if err != nil {
return err
}
if uid == id || currentUser.IsAdmin || currentUser.IsCommunityAdmin {
return c.Status(fiber.StatusOK).JSON(models.OKResponse{
Data: response,
Error: false,
})
} else {
if !(uid == id || currentUser.IsAdmin || currentUser.IsCommunityAdmin) {
response.Reward = -1
return c.Status(fiber.StatusOK).JSON(models.OKResponse{
Data: response,
Error: false,
})
}
return c.Status(fiber.StatusOK).JSON(models.OKResponse{
Data: response,
Error: false,
})
}

0 comments on commit 88ce7f3

Please sign in to comment.