Codemaxxers / Issues

0 stars 0 forks source link

Documenting: leaderboard of top 5 cspPoints/csaPoints #14

Open TheoH32 opened 6 months ago

TheoH32 commented 6 months ago

How it works

    List<Person> findTop5ByOrderByCspPointsDesc();

    List<Person> findTop5ByOrderByCsaPointsDesc();

    @Query("SELECT p FROM Person p ORDER BY p.cspPoints DESC")
    List<Person> findTop5ByCspPoints();

    @Query("SELECT p FROM Person p ORDER BY p.csaPoints DESC")
    List<Person> findTop5ByCsaPoints();

It can be done in two different ways with the result being the same. First, there is the list, then the query option. Both have advantages and disadvantages but it depends on what your project/goal is. I recommend trying both to see if there is any major differences in efficiency.

Get Mapping

    @GetMapping("/leaderboardCSP")
    public List<Person> getLeaderboardCSP() {
        // Get top 5 users based on cspPoints
        return repository.findTop5ByOrderByCspPointsDesc();
    }

    @GetMapping("/leaderboardCSA")
    public List<Person> getLeaderboardCSA() {
        // Get top 5 users based on cspPoints
        return repository.findTop5ByOrderByCsaPointsDesc();
    }

Basically, when anyone sends a GET request to these endpoints, it uses the functions shown above to sort and find the top 5 users with the highest points. My plan is that whenever the user goes on the leaderboard page on the frontend, it sends a GET request to the backend and populates the table

TheoH32 commented 6 months ago

https://github.com/Codemaxxers/codemaxxerBackend/pull/7/files