44import com .faforever .api .data .domain .UserGroup ;
55import com .faforever .api .player .PlayerService ;
66import com .faforever .api .security .FafUserDetails ;
7- import com .faforever .api .web .JsonApiSingleResource ;
7+ import com .google .common .collect .ImmutableMap ;
8+ import com .yahoo .elide .jsonapi .models .Data ;
9+ import com .yahoo .elide .jsonapi .models .JsonApiDocument ;
10+ import com .yahoo .elide .jsonapi .models .Resource ;
811import io .swagger .annotations .ApiOperation ;
912import io .swagger .annotations .ApiResponse ;
1013import lombok .Builder ;
1619import org .springframework .web .bind .annotation .RequestMethod ;
1720import org .springframework .web .bind .annotation .RestController ;
1821
22+ import java .util .Optional ;
1923import java .util .Set ;
2024import java .util .stream .Collectors ;
2125
@@ -34,7 +38,7 @@ public MeController(PlayerService playerService) {
3438 @ ApiOperation ("Returns the authentication object of the current user" )
3539 @ ApiResponse (code = 200 , message = "Success with JsonApi compliant MeResult" )
3640 @ Secured ("ROLE_USER" )
37- public JsonApiSingleResource < MeResult > me (@ AuthenticationPrincipal FafUserDetails authentication ) {
41+ public JsonApiDocument me (@ AuthenticationPrincipal FafUserDetails authentication ) {
3842
3943 Player player = playerService .getById (authentication .getId ());
4044 Set <String > grantedAuthorities = authentication .getAuthorities ().stream ()
@@ -45,41 +49,27 @@ public JsonApiSingleResource<MeResult> me(@AuthenticationPrincipal FafUserDetail
4549 .map (UserGroup ::getTechnicalName )
4650 .collect (Collectors .toSet ());
4751
48- return MeResult .builder ()
49- .userId (player .getId ())
50- .userName (player .getLogin ())
51- .email (player .getEmail ())
52- .clan (player .getClan () == null ? null : Clan .builder ()
53- .id (player .getClan ().getId ())
54- .membershipId (player .getClanMembership ().getId ())
55- .tag (player .getClan ().getTag ())
56- .name (player .getClan ().getName ())
57- .build ()
52+ return new JsonApiDocument (new Data <>(
53+ new Resource ("me" ,
54+ "me" ,
55+ ImmutableMap .<String , Object >builder ()
56+ .put ("userId" , player .getId ())
57+ .put ("userName" , player .getLogin ())
58+ .put ("email" , player .getEmail ())
59+ .put ("clan" , player .getClan () == null ? Optional .empty () : Clan .builder ()
60+ .id (player .getClan ().getId ())
61+ .membershipId (player .getClanMembership ().getId ())
62+ .tag (player .getClan ().getTag ())
63+ .name (player .getClan ().getName ())
64+ .build ())
65+ .put ("groups" , groups )
66+ .put ("permissions" , grantedAuthorities )
67+ .build (),
68+ null ,
69+ null ,
70+ null
5871 )
59- .groups (groups )
60- .permissions (grantedAuthorities )
61- .build ()
62- .asJsonApi ();
63- }
64-
65- @ Value
66- @ Builder
67- public static class MeResult {
68- Integer userId ;
69- String userName ;
70- String email ;
71- Clan clan ;
72- Set <String > groups ;
73- Set <String > permissions ;
74-
75- @ SuppressWarnings ("unchecked" )
76- JsonApiSingleResource <MeResult > asJsonApi () {
77- return JsonApiSingleResource .ofProxy (
78- () -> "me" ,
79- () -> "me" ,
80- () -> this
81- );
82- }
72+ ));
8373 }
8474
8575 @ Value
0 commit comments