Search in sources :

Example 1 with ResourceNotFoundException

use of com.faforever.api.web.ResourceNotFoundException in project faf-java-api by FAForever.

the class LeaderboardController method getSingleGlobal.

@Async
@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));
    if (entry == null) {
        throw new ResourceNotFoundException("No global leaderboard entry found for player: " + playerId);
    }
    Resource resource = new Resource(GLOBAL_LEADERBOARD_ENTRY, playerId, ImmutableMap.<String, Object>builder().put("name", entry.getPlayerName()).put("mean", entry.getMean()).put("deviation", entry.getDeviation()).put("numGames", entry.getNumGames()).put("rank", entry.getRank()).put("rating", (int) (entry.getMean() - 3 * entry.getDeviation())).build(), null, null, null);
    return CompletableFuture.completedFuture(new JsonApiDocument(new Data<>(resource)));
}
Also used : JsonApiDocument(com.yahoo.elide.jsonapi.models.JsonApiDocument) Resource(com.yahoo.elide.jsonapi.models.Resource) Data(com.yahoo.elide.jsonapi.models.Data) ResourceNotFoundException(com.faforever.api.web.ResourceNotFoundException) Async(org.springframework.scheduling.annotation.Async) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ResourceNotFoundException

use of com.faforever.api.web.ResourceNotFoundException in project faf-java-api by FAForever.

the class LeaderboardController method getSingleLadder1v1.

@Async
@RequestMapping(path = "/ladder1v1/{playerId}", method = RequestMethod.GET)
@ApiOperation("Lists the ladder1v1 leaderboard for the specified player")
public CompletableFuture<JsonApiDocument> getSingleLadder1v1(@PathVariable("playerId") String playerId) {
    Ladder1v1LeaderboardEntry entry = leaderboardService.getLadder1v1Entry(Integer.valueOf(playerId));
    if (entry == null) {
        throw new ResourceNotFoundException("No ladder1v1 entry found for player: " + playerId);
    }
    Resource resource = new Resource(LADDER_1V1_LEADERBOARD_ENTRY, playerId, ImmutableMap.<String, Object>builder().put("name", entry.getPlayerName()).put("mean", entry.getMean()).put("deviation", entry.getDeviation()).put("numGames", entry.getNumGames()).put("wonGames", entry.getWonGames()).put("rank", entry.getRank()).put("rating", (int) (entry.getMean() - 3 * entry.getDeviation())).build(), null, null, null);
    return CompletableFuture.completedFuture(new JsonApiDocument(new Data<>(resource)));
}
Also used : JsonApiDocument(com.yahoo.elide.jsonapi.models.JsonApiDocument) Resource(com.yahoo.elide.jsonapi.models.Resource) Data(com.yahoo.elide.jsonapi.models.Data) ResourceNotFoundException(com.faforever.api.web.ResourceNotFoundException) Async(org.springframework.scheduling.annotation.Async) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResourceNotFoundException (com.faforever.api.web.ResourceNotFoundException)2 Data (com.yahoo.elide.jsonapi.models.Data)2 JsonApiDocument (com.yahoo.elide.jsonapi.models.JsonApiDocument)2 Resource (com.yahoo.elide.jsonapi.models.Resource)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Async (org.springframework.scheduling.annotation.Async)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2