Skip to content

Commit

Permalink
fix(queries.GetProfile): set reward in profile response to anonymous …
Browse files Browse the repository at this point in the history
…user to -1
  • Loading branch information
AstatineAi committed May 23, 2024
1 parent 439a5c1 commit ed23695
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions pkg/queries/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,20 +375,33 @@ func GetProfile(db *gorm.DB, queriedUserID uint, queryingUserID uint) (models.Pr
if user.Avatar != "" {
avatar = fmt.Sprintf("https://%s/%s/avatar/%s", database.GetEndpoint(), database.MinioConf.Bucket, user.Avatar)
}
if user.IsAnonymous && queryingUserID != queriedUserID {
return models.ProfileResponse{ID: user.ID, NickName: user.NickName, Avatar: avatar, IsAnonymous: user.IsAnonymous, IsAdmin: user.IsAdmin, IsCommunityAdmin: user.IsCommunityAdmin}, nil
r := models.ProfileResponse{
ID: user.ID,
NickName: user.NickName,
Avatar: avatar,
IsAnonymous: user.IsAnonymous,
IsAdmin: user.IsAdmin,
IsCommunityAdmin: user.IsCommunityAdmin,
}

if !user.IsAnonymous || queryingUserID == queriedUserID {
r.Email = user.Email
r.Year = user.Year
r.Grade = user.Grade
r.RealName = user.RealName
}

if displayInvitationCode {
r.InvitationCode = user.InvitationCode
}

if displayReward {
r.Reward = user.Reward
} else {
r := models.ProfileResponse{ID: user.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 displayInvitationCode {
r.InvitationCode = user.InvitationCode
}
if displayReward {
r.Reward = user.Reward
} else {
r.Reward = -1
}
return r, nil
r.Reward = -1
}

return r, nil
}

func CheckYear(year int) bool {
Expand Down

0 comments on commit ed23695

Please sign in to comment.