1212import io .swagger .annotations .ApiResponses ;
1313import lombok .RequiredArgsConstructor ;
1414import org .springframework .security .access .prepost .PreAuthorize ;
15- import org .springframework .security .core .Authentication ;
1615import org .springframework .transaction .annotation .Transactional ;
1716import org .springframework .web .bind .annotation .RequestMapping ;
1817import org .springframework .web .bind .annotation .RequestMethod ;
1918import org .springframework .web .bind .annotation .RequestParam ;
2019import org .springframework .web .bind .annotation .RestController ;
2120
22- import java .io .IOException ;
2321import java .io .Serializable ;
2422import java .util .Map ;
2523
26- import static org .springframework .http .MediaType .APPLICATION_JSON_UTF8_VALUE ;
24+ import static org .springframework .http .MediaType .APPLICATION_JSON_VALUE ;
2725
2826
2927@ RestController
@@ -37,11 +35,12 @@ public class ClansController {
3735
3836 @ ApiOperation ("Grab data about yourself and the clan" )
3937 @ ApiResponses (value = {
40- @ ApiResponse (code = 200 , message = "Success with JSON { player: {id: ?, login: ?}, clan: { id: ?, name: ?, tag: ?}}" ),
41- @ ApiResponse (code = 400 , message = "Bad Request" )})
42- @ RequestMapping (path = "/me" , method = RequestMethod .GET , produces = APPLICATION_JSON_UTF8_VALUE )
43- public MeResult me (Authentication authentication ) {
44- Player player = playerService .getPlayer (authentication );
38+ @ ApiResponse (code = 200 , message = "Success with JSON { player: {id: ?, login: ?}, clan: { id: ?, name: ?, tag: ?}}" ),
39+ @ ApiResponse (code = 400 , message = "Bad Request" )})
40+ @ RequestMapping (path = "/me" , method = RequestMethod .GET , produces = APPLICATION_JSON_VALUE )
41+ @ Deprecated // use regular /me route instead
42+ public MeResult me () {
43+ Player player = playerService .getCurrentPlayer ();
4544
4645 Clan clan = player .getClan ();
4746 ClanResult clanResult = null ;
@@ -55,44 +54,36 @@ public MeResult me(Authentication authentication) {
5554 // a: the new clan with the leader membership, b: the leader membership with the new clan
5655 @ ApiOperation ("Create a clan with correct leader, founder and clan membership" )
5756 @ ApiResponses (value = {
58- @ ApiResponse (code = 200 , message = "Success with JSON { id: ?, type: 'clan'}" ),
59- @ ApiResponse (code = 400 , message = "Bad Request" )})
60- @ RequestMapping (path = "/create" , method = RequestMethod .POST , produces = APPLICATION_JSON_UTF8_VALUE )
57+ @ ApiResponse (code = 200 , message = "Success with JSON { id: ?, type: 'clan'}" ),
58+ @ ApiResponse (code = 400 , message = "Bad Request" )})
59+ @ RequestMapping (path = "/create" , method = RequestMethod .POST , produces = APPLICATION_JSON_VALUE )
6160 @ PreAuthorize ("hasRole('ROLE_USER')" )
6261 @ Transactional
62+ @ Deprecated // use POST /data/clans instead (with a founder in relationships)
6363 public Map <String , Serializable > createClan (@ RequestParam (value = "name" ) String name ,
6464 @ RequestParam (value = "tag" ) String tag ,
65- @ RequestParam (value = "description" , required = false ) String description ,
66- Authentication authentication ) throws IOException {
67- Player player = playerService .getPlayer (authentication );
68- Clan clan = clanService .create (name , tag , description , player );
65+ @ RequestParam (value = "description" , required = false ) String description ) {
66+ Player player = playerService .getCurrentPlayer ();
67+ Clan clan = clanService .create (name , tag , description );
6968 return ImmutableMap .of ("id" , clan .getId (), "type" , "clan" );
7069 }
7170
7271 @ ApiOperation ("Generate invitation link" )
7372 @ ApiResponses (value = {
74- @ ApiResponse (code = 200 , message = "Success with JSON { jwtToken: ? }" ),
75- @ ApiResponse (code = 400 , message = "Bad Request" )})
76- @ RequestMapping (path = "/generateInvitationLink" ,
77- method = RequestMethod .GET ,
78- produces = APPLICATION_JSON_UTF8_VALUE )
73+ @ ApiResponse (code = 200 , message = "Success with JSON { jwtToken: ? }" ),
74+ @ ApiResponse (code = 400 , message = "Bad Request" )})
75+ @ RequestMapping (path = "/generateInvitationLink" , method = RequestMethod .GET , produces = APPLICATION_JSON_VALUE )
7976 public Map <String , Serializable > generateInvitationLink (
80- @ RequestParam (value = "clanId" ) int clanId ,
81- @ RequestParam (value = "playerId" ) int newMemberId ,
82- Authentication authentication ) throws IOException {
83- Player player = playerService .getPlayer (authentication );
84- String jwtToken = clanService .generatePlayerInvitationToken (player , newMemberId , clanId );
77+ @ RequestParam (value = "clanId" ) int clanId ,
78+ @ RequestParam (value = "playerId" ) int newMemberId ) {
79+ String jwtToken = clanService .generatePlayerInvitationToken (newMemberId , clanId );
8580 return ImmutableMap .of ("jwtToken" , jwtToken );
8681 }
8782
8883 @ ApiOperation ("Check invitation link and add Member to Clan" )
89- @ RequestMapping (path = "/joinClan" ,
90- method = RequestMethod .POST ,
91- produces = APPLICATION_JSON_UTF8_VALUE )
84+ @ RequestMapping (path = "/joinClan" , method = RequestMethod .POST , produces = APPLICATION_JSON_VALUE )
9285 @ Transactional
93- public void joinClan (
94- @ RequestParam (value = "token" ) String stringToken ,
95- Authentication authentication ) throws IOException {
96- clanService .acceptPlayerInvitationToken (stringToken , authentication );
86+ public void joinClan (@ RequestParam (value = "token" ) String stringToken ) {
87+ clanService .acceptPlayerInvitationToken (stringToken );
9788 }
9889}
0 commit comments