Skip to content

feat: implement test score leaderboard with ranking, filtering, and cursor pagination#452

Open
Shadow-MMN wants to merge 5 commits into
StarkMindsHQ:mainfrom
Shadow-MMN:feat/test-score-leaderboard
Open

feat: implement test score leaderboard with ranking, filtering, and cursor pagination#452
Shadow-MMN wants to merge 5 commits into
StarkMindsHQ:mainfrom
Shadow-MMN:feat/test-score-leaderboard

Conversation

@Shadow-MMN
Copy link
Copy Markdown

Summary

Implements a full "Leaderboard for Test Scores" feature, including backend API, database schema, and frontend UI.

Key Features

  • Ranking: Shared (competition ranking, e.g. 1,2,2,4) using SQL RANK()
  • Filtering: Server-side filtering by courseId and testId
  • Pagination: Cursor-based pagination for scalability
  • Sorting: Supports score (default), timeSpent, and attempts
  • Current User: Highlighted in leaderboard + surfaced even if outside current page

API

GET /api/leaderboard/test-scores

Supports:

  • courseId
  • testId
  • sortBy (score | timeSpent | attempts)
  • order (asc | desc)
  • limit (default 20, max 100)
  • cursor

Returns:

  • paginated ranked data
  • nextCursor + hasMore
  • totalCount
  • currentUserEntry (if applicable)

Database

  • Added QuizAttempt model
  • Indexed critical fields (userId, quizId, courseId, score, completedAt)
  • Optimized queries using window functions and joins

Frontend

  • Leaderboard component with:
    • rank, score, and user display
    • current user highlight ("You" badge)
    • top 3 visual indicators
    • load more pagination
    • sorting controls
  • Handles loading, empty, and error states

Performance Considerations

  • No OFFSET pagination (cursor-based)
  • DB-level ranking and filtering
  • Indexed queries
  • Minimal queries (single main query + optional current user lookup)

Notes

Many files were corrected which doesn't concern to the issue given to me but they were bugs I need to fix to keep the app working well. So my PR will have a lot of changes not concerning the issue.

Closes #379

…ursor pagination

- add QuizAttempt model with relations and indexed fields
- implement GET /api/leaderboard/test-scores endpoint
- support filtering by courseId and testId
- add sorting (score, timeSpent, attempts) with configurable order
- implement shared ranking (RANK window function)
- add cursor-based pagination with deterministic ordering
- return currentUserEntry for highlighting outside current page
- create TestScoreLeaderboard React component with:
  - current user highlighting
  - load more pagination
  - sorting controls
  - top 3 badges and formatted display
- add API and component test coverage (all passing)
- ensure performance via DB-level sorting, indexing, and no OFFSET usage
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 25, 2026

@Shadow-MMN Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Shadow-MMN
Copy link
Copy Markdown
Author

@lishmanTech can we check this out now?

@Shadow-MMN
Copy link
Copy Markdown
Author

@lishmanTech can we check this out now ?

@Shadow-MMN
Copy link
Copy Markdown
Author

@LaGodxy can we check this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leaderboard for Test Scores Component

1 participant