Implement Leaderboard Service#29
Open
VishakhaSainani-Josh wants to merge 3 commits intofeat/transaction-servicefrom
Open
Implement Leaderboard Service#29VishakhaSainani-Josh wants to merge 3 commits intofeat/transaction-servicefrom
VishakhaSainani-Josh wants to merge 3 commits intofeat/transaction-servicefrom
Conversation
Collaborator
VishakhaSainani-Josh
commented
Jul 11, 2025
- Get all users ranking
- Get current user ranking
internal/app/user/service.go
Outdated
|
|
||
| serviceLeaderboard := make([]LeaderboardUser, len(leaderboard)) | ||
| for i, l := range leaderboard { | ||
| serviceLeaderboard[i] = LeaderboardUser((l)) |
Collaborator
There was a problem hiding this comment.
extra bracket
internal/app/user/service.go
Outdated
| } | ||
|
|
||
| func (s *service) GetAllUsersRank(ctx context.Context) ([]LeaderboardUser, error) { | ||
| leaderboard, err := s.userRepository.GetAllUsersRank(ctx, nil) |
Collaborator
There was a problem hiding this comment.
leaderboard naming is bit confusing, could you change it.
userRanks would be good, so that can update the serviceLeaderboard to leaderboard if needed.
Comment on lines
+58
to
+66
| getAllUsersRankQuery = ` | ||
| SELECT | ||
| id, | ||
| github_username, | ||
| avatar_url, | ||
| current_balance, | ||
| RANK() over (ORDER BY current_balance DESC) AS rank | ||
| FROM users | ||
| ORDER BY current_balance DESC` |
Collaborator
There was a problem hiding this comment.
Do we have index on current_balance?, would be good to add an index on it when using RANK()
CREATE INDEX idx_users_current_balance ON users(current_balance DESC);
internal/repository/user.go
Outdated
| } | ||
|
|
||
| func (ur *userRepository) GetCurrentUserRank(ctx context.Context, tx *sqlx.Tx) (LeaderboardUser, error) { | ||
| userIdValue := ctx.Value(middleware.UserIdKey) |
Collaborator
There was a problem hiding this comment.
read ctx in handler, and pass it through service and then repo.
Keep repo layer independent of context value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.