-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Leaderboard Service #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/transaction-service
Are you sure you want to change the base?
Implement Leaderboard Service #29
Conversation
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra bracket
internal/app/user/service.go
Outdated
| } | ||
|
|
||
| func (s *service) GetAllUsersRank(ctx context.Context) ([]LeaderboardUser, error) { | ||
| leaderboard, err := s.userRepository.GetAllUsersRank(ctx, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leaderboard naming is bit confusing, could you change it.
userRanks would be good, so that can update the serviceLeaderboard to leaderboard if needed.
| 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` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read ctx in handler, and pass it through service and then repo.
Keep repo layer independent of context value.