11package com .faforever .api .featuredmods ;
22
33import com .faforever .api .data .domain .FeaturedMod ;
4+ import com .faforever .api .error .ApiException ;
5+ import com .faforever .api .error .Error ;
46import com .faforever .api .security .OAuthScope ;
5- import com .google .common .collect .Maps ;
67import com .yahoo .elide .jsonapi .models .Data ;
78import com .yahoo .elide .jsonapi .models .JsonApiDocument ;
89import com .yahoo .elide .jsonapi .models .Resource ;
910import io .swagger .annotations .ApiOperation ;
10- import org .springframework .scheduling .annotation .Async ;
1111import org .springframework .security .access .prepost .PreAuthorize ;
1212import org .springframework .web .bind .annotation .PathVariable ;
1313import org .springframework .web .bind .annotation .RequestMapping ;
1717import java .util .List ;
1818import java .util .Map ;
1919import java .util .Optional ;
20- import java .util .concurrent .CompletableFuture ;
2120import java .util .function .Function ;
2221
22+ import static com .faforever .api .error .ErrorCode .FEATURED_MOD_UNKNOWN ;
23+
2324@ RestController
2425@ RequestMapping (path = "/featuredMods" )
2526public class FeaturedModsController {
@@ -30,28 +31,27 @@ public FeaturedModsController(FeaturedModService featuredModService) {
3031 this .featuredModService = featuredModService ;
3132 }
3233
33- @ Async
3434 @ RequestMapping (path = "/{modId}/files/{version}" )
3535 @ ApiOperation ("Lists the required files for a specific featured mod version" )
3636 @ PreAuthorize ("hasScope('" + OAuthScope ._LOBBY + "')" )
37- public CompletableFuture < JsonApiDocument > getFiles (@ PathVariable ("modId" ) int modId ,
38- @ PathVariable ("version" ) String version ,
39- @ RequestParam (value = "page[number]" , required = false ) Integer page ) {
37+ public JsonApiDocument getFiles (@ PathVariable ("modId" ) int modId ,
38+ @ PathVariable ("version" ) String version ,
39+ @ RequestParam (value = "page[number]" , required = false ) Integer page ) {
4040 Integer innerPage = Optional .ofNullable (page ).orElse (0 );
4141 if (innerPage > 1 ) {
42- return CompletableFuture . completedFuture ( new JsonApiDocument (new Data <>(List .of () )));
42+ return new JsonApiDocument (new Data <>(List .of ()));
4343 }
4444
45- Map < Integer , FeaturedMod > mods = Maps . uniqueIndex ( featuredModService .getFeaturedMods (), FeaturedMod :: getId );
46- FeaturedMod featuredMod = mods . get ( modId );
45+ FeaturedMod featuredMod = featuredModService .findModById ( modId )
46+ . orElseThrow (() -> new ApiException ( new Error ( FEATURED_MOD_UNKNOWN , modId )) );
4747
4848 Integer innerVersion = "latest" .equals (version ) ? null : Integer .valueOf (version );
4949
5050 List <Resource > values = featuredModService .getFiles (featuredMod .getTechnicalName (), innerVersion ).stream ()
51- .map (modFileMapper ())
52- .toList ();
51+ .map (modFileMapper ())
52+ .toList ();
5353
54- return CompletableFuture . completedFuture ( new JsonApiDocument (new Data <>(values ) ));
54+ return new JsonApiDocument (new Data <>(values ));
5555 }
5656
5757 private Function <FeaturedModFile , Resource > modFileMapper () {
0 commit comments