Search in sources :

Example 11 with Data

use of com.yahoo.elide.jsonapi.models.Data in project faf-java-api by FAForever.

the class FeaturedModsController method getFiles.

@Async
@RequestMapping(path = "/{modId}/files/{version}")
@ApiOperation("Lists the required files for a specific featured mod version")
public CompletableFuture<JsonApiDocument> getFiles(@PathVariable("modId") int modId, @PathVariable("version") String version, @RequestParam(value = "page[number]", required = false) Integer page) {
    Integer innerPage = Optional.ofNullable(page).orElse(0);
    if (innerPage > 1) {
        return CompletableFuture.completedFuture(new JsonApiDocument(new Data<>(Collections.emptyList())));
    }
    ImmutableMap<Integer, FeaturedMod> mods = Maps.uniqueIndex(featuredModService.getFeaturedMods(), FeaturedMod::getId);
    FeaturedMod featuredMod = mods.get(modId);
    Integer innerVersion = "latest".equals(version) ? null : Integer.valueOf(version);
    List<Resource> values = featuredModService.getFiles(featuredMod.getTechnicalName(), innerVersion).stream().map(modFileMapper()).collect(Collectors.toList());
    return CompletableFuture.completedFuture(new JsonApiDocument(new Data<>(values)));
}
Also used : JsonApiDocument(com.yahoo.elide.jsonapi.models.JsonApiDocument) Resource(com.yahoo.elide.jsonapi.models.Resource) Data(com.yahoo.elide.jsonapi.models.Data) FeaturedMod(com.faforever.api.data.domain.FeaturedMod) Async(org.springframework.scheduling.annotation.Async) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Data (com.yahoo.elide.jsonapi.models.Data)11 Resource (com.yahoo.elide.jsonapi.models.Resource)10 JsonApiDocument (com.yahoo.elide.jsonapi.models.JsonApiDocument)8 PersistentResource (com.yahoo.elide.core.PersistentResource)5 Test (org.junit.jupiter.api.Test)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ArrayList (java.util.ArrayList)3 Async (org.springframework.scheduling.annotation.Async)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResourceNotFoundException (com.faforever.api.web.ResourceNotFoundException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 RequestScope (com.yahoo.elide.core.RequestScope)2 JsonApiMapper (com.yahoo.elide.jsonapi.JsonApiMapper)2 Relationship (com.yahoo.elide.jsonapi.models.Relationship)2 FeaturedMod (com.faforever.api.data.domain.FeaturedMod)1 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)1 RelationshipType (com.yahoo.elide.core.dictionary.RelationshipType)1 TestUser (com.yahoo.elide.core.security.TestUser)1 User (com.yahoo.elide.core.security.User)1 DocumentProcessor (com.yahoo.elide.jsonapi.document.processors.DocumentProcessor)1