Skip to content

Commit

Permalink
refactor: move personal reward display condition into pkg/queries/use…
Browse files Browse the repository at this point in the history
…r.go.
  • Loading branch information
Tanngent2005 committed Apr 10, 2024
1 parent 11d169f commit 5aa4c2d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
7 changes: 0 additions & 7 deletions internal/controllers/users/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ func Profile(c *fiber.Ctx) error {
if err != nil {
return err
}
currentUser, err := queries.GetUserByID(nil, uid)
if err != nil {
return err
}
if !(uid == id || currentUser.IsAdmin || currentUser.IsCommunityAdmin) {
response.Reward = -1
}
return c.Status(fiber.StatusOK).JSON(models.OKResponse{
Data: response,
Error: false,
Expand Down
4 changes: 3 additions & 1 deletion pkg/queries/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,14 @@ func GetProfile(db *gorm.DB, id uint, uid uint) (models.ProfileResponse, error)
if user.IsAnonymous && id != uid {
return models.ProfileResponse{ID: id, NickName: user.NickName, Avatar: avatar, IsAnonymous: user.IsAnonymous, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin}, nil
} else {
r := models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin, Reward: user.Reward}
r := models.ProfileResponse{ID: id, Email: user.Email, Year: user.Year, Grade: user.Grade, NickName: user.NickName, RealName: user.RealName, IsAnonymous: user.IsAnonymous, Avatar: avatar, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin}
if id == uid {
r.InvitationCode = user.InvitationCode
}
if id == uid || user.IsAdmin || user.IsCommunityAdmin {
r.Reward = user.Reward
} else {
r.Reward = -1
}
return r, nil
}
Expand Down

0 comments on commit 5aa4c2d

Please sign in to comment.