Skip to content

Commit

Permalink
Merge 84ffde8 into c8c5663
Browse files Browse the repository at this point in the history
  • Loading branch information
Padmanabhan Manoharan committed Oct 3, 2019
2 parents c8c5663 + 84ffde8 commit 35f343f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/main/java/com/faforever/api/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public enum ErrorCode {
PARSING_LUA_FILE_FAILED(189, "Parsing lua files failed", "During the parsing of the lua file an error occured: {0}"),
NO_RUSH_RADIUS_MISSING(190, "No rush radius missing", "The scenario file must specify a no rush radius"),
INVALID_FEATURED_MOD(191, "Invalid featured mod name", "The featured mod name ''{0}'' is not allowed in this context."),
API_KEY_INVALID(192, "Api key is invalid", "The api key is invalid.");

API_KEY_INVALID(192, "Api key is invalid", "The api key is invalid."),
PLAYER_ID_MUST_BE_NUMBER(193,"Player ID must be number","The player id must be a number");
private final int code;
private final String title;
private final String detail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public CompletableFuture<JsonApiDocument> getSingleLadder1v1(@PathVariable("play
@RequestMapping(path = "/global/{playerId}", method = RequestMethod.GET)
@ApiOperation("Lists the global leaderboard for the specified player")
public CompletableFuture<JsonApiDocument> getSingleGlobal(@PathVariable("playerId") String playerId) {
GlobalLeaderboardEntry entry = leaderboardService.getGlobalEntry(Integer.valueOf(playerId));
GlobalLeaderboardEntry entry = leaderboardService.getGlobalEntry(playerId);
if (entry == null) {
throw new ResourceNotFoundException("No global leaderboard entry found for player: " + playerId);
throw new ResourceNotFoundException("No global leader board entry found for player: " + playerId);
}

Resource resource = new Resource(GLOBAL_LEADERBOARD_ENTRY, playerId, ImmutableMap.<String, Object>builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.faforever.api.leaderboard;

import com.faforever.api.error.ApiException;
import com.faforever.api.error.ErrorCode;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.cache.annotation.Cacheable;
Expand Down Expand Up @@ -35,8 +38,11 @@ public Page<GlobalLeaderboardEntry> getGlobalLeaderboard(@Nullable Integer page,
return globalLeaderboardRepository.getLeaderboardByPage(getPageable(page, pageSize));
}

public GlobalLeaderboardEntry getGlobalEntry(int playerId) {
return globalLeaderboardRepository.findByPlayerId(playerId);
public GlobalLeaderboardEntry getGlobalEntry(String playerId) {
if (!StringUtils.isNumeric(playerId)) {
throw ApiException.of(ErrorCode.PLAYER_ID_MUST_BE_NUMBER);
}
return globalLeaderboardRepository.findByPlayerId(Integer.parseInt(playerId));
}

public Ladder1v1LeaderboardEntry getLadder1v1Entry(int playerId) {
Expand Down

0 comments on commit 35f343f

Please sign in to comment.