Manually auth for Leaderboard
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good

This commit is contained in:
2026-01-23 15:09:22 +01:00
parent b4d6c1ea13
commit edabef4fb3
3 changed files with 21 additions and 21 deletions
@@ -32,10 +32,9 @@ class LeaderboardController {
})
@GetMapping("/getLeaderboard")
public ResponseEntity<Leaderboard> getLeaderboard(@AuthenticationPrincipal User user,
@RequestParam Timeframe timeframe,
public ResponseEntity<Leaderboard> getLeaderboard(@RequestParam Timeframe timeframe,
@RequestParam String field) {
Leaderboard leaderboard = this.leaderboardService.getLeaderboard(user, timeframe, field);
Leaderboard leaderboard = this.leaderboardService.getLeaderboard(timeframe, field);
return ResponseEntity.status(HttpStatus.OK).body(leaderboard);
}
@@ -45,10 +44,9 @@ class LeaderboardController {
@ApiResponse(responseCode = "400", description = "Bad request")
})
@GetMapping("/getFriendLeaderboard")
public ResponseEntity<Leaderboard> getFriendLeaderboard(@AuthenticationPrincipal User user,
@RequestParam Timeframe timeframe,
public ResponseEntity<Leaderboard> getFriendLeaderboard(@RequestParam Timeframe timeframe,
@RequestParam String field) {
Leaderboard leaderboard = this.leaderboardService.getFriendLeaderboard(user, timeframe, field);
Leaderboard leaderboard = this.leaderboardService.getFriendLeaderboard(timeframe, field);
return ResponseEntity.status(HttpStatus.OK).body(leaderboard);
}
}
@@ -4,6 +4,7 @@ import SuMoC.backend.gamification.scoretable.models.Leaderboard;
import SuMoC.backend.gamification.Timeframe;
import SuMoC.backend.gamification.scoretable.models.LeaderboardEntry;
import SuMoC.backend.user.models.User;
import SuMoC.backend.user.service.CurrentUserService;
import SuMoC.backend.user.service.FriendshipService;
import SuMoC.backend.user.stats.*;
import org.springframework.data.domain.PageRequest;
@@ -21,36 +22,37 @@ import java.util.stream.Collectors;
public class LeaderboardService {
private final FriendshipService friendshipService;
private final StatsListRepository statsListRepository;
private final CurrentUserService currentUser;
public LeaderboardService(
FriendshipService friendshipService,
StatsListRepository statsListRepository
) {
StatsListRepository statsListRepository,
CurrentUserService currentUserService) {
this.friendshipService = friendshipService;
this.statsListRepository = statsListRepository;
this.currentUser = currentUserService;
}
/**
* Method Overload to get the score table with a default limit of 30.
* @param user
* @param timeframe
* @param field
* @return
*/
public Leaderboard getLeaderboard(User user, Timeframe timeframe, String field) {
return getLeaderboard(user, timeframe, field, 30);
public Leaderboard getLeaderboard(Timeframe timeframe, String field) {
return getLeaderboard(timeframe, field, 30);
}
/**
* Get the global score table for a given user, timeframe, score type, and limit.
* @param user
* @param timeframe
* @param field
* @param limit
* @return
*/
public Leaderboard getLeaderboard(User user, Timeframe timeframe, String field, int limit) {
public Leaderboard getLeaderboard(Timeframe timeframe, String field, int limit) {
User user = currentUser.get();
List<StatsList> topStats = getTopStats(timeframe, field, limit);
List<Long> topUserIds = topStats.stream()
@@ -108,20 +110,20 @@ public class LeaderboardService {
* @param field
* @return
*/
public Leaderboard getFriendLeaderboard(User user, Timeframe timeframe, String field) {
return getFriendLeaderboard(user, timeframe, field, 30);
public Leaderboard getFriendLeaderboard(Timeframe timeframe, String field) {
return getFriendLeaderboard(timeframe, field, 30);
}
/**
* Get the friend score table for a given user, timeframe, score type, and limit.
* @param user
* @param timeframe
* @param field
* @param limit
* @return
*/
public Leaderboard getFriendLeaderboard(User user, Timeframe timeframe, String field, int limit) {
public Leaderboard getFriendLeaderboard(Timeframe timeframe, String field, int limit) {
User user = currentUser.get();
List<User> friends = friendshipService.getAcceptedFriends(user);
Leaderboard leaderboard = new Leaderboard();