66import com .faforever .api .data .domain .Clan ;
77import com .faforever .api .data .domain .Player ;
88import com .faforever .api .player .PlayerService ;
9- import com .google .common .collect .ImmutableMap ;
109import io .swagger .annotations .ApiOperation ;
1110import io .swagger .annotations .ApiResponse ;
1211import io .swagger .annotations .ApiResponses ;
1312import lombok .RequiredArgsConstructor ;
1413import org .springframework .security .access .prepost .PreAuthorize ;
15- import org .springframework .security . core . Authentication ;
16- import org .springframework .transaction . annotation .Transactional ;
14+ import org .springframework .web . bind . annotation . GetMapping ;
15+ import org .springframework .web . bind . annotation .PostMapping ;
1716import org .springframework .web .bind .annotation .RequestMapping ;
18- import org .springframework .web .bind .annotation .RequestMethod ;
1917import org .springframework .web .bind .annotation .RequestParam ;
2018import org .springframework .web .bind .annotation .RestController ;
2119
22- import java .io .IOException ;
2320import java .io .Serializable ;
2421import java .util .Map ;
2522
26- import static org .springframework .http .MediaType .APPLICATION_JSON_UTF8_VALUE ;
23+ import static org .springframework .http .MediaType .APPLICATION_JSON_VALUE ;
2724
2825
2926@ RestController
@@ -37,11 +34,12 @@ public class ClansController {
3734
3835 @ ApiOperation ("Grab data about yourself and the clan" )
3936 @ 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 );
37+ @ ApiResponse (code = 200 , message = "Success with JSON { player: {id: ?, login: ?}, clan: { id: ?, name: ?, tag: ?}}" ),
38+ @ ApiResponse (code = 400 , message = "Bad Request" )})
39+ @ GetMapping (path = "/me" , produces = APPLICATION_JSON_VALUE )
40+ @ Deprecated // use regular /me route instead
41+ public MeResult me () {
42+ Player player = playerService .getCurrentPlayer ();
4543
4644 Clan clan = player .getClan ();
4745 ClanResult clanResult = null ;
@@ -55,44 +53,33 @@ public MeResult me(Authentication authentication) {
5553 // a: the new clan with the leader membership, b: the leader membership with the new clan
5654 @ ApiOperation ("Create a clan with correct leader, founder and clan membership" )
5755 @ 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 )
56+ @ ApiResponse (code = 200 , message = "Success with JSON { id: ?, type: 'clan'}" ),
57+ @ ApiResponse (code = 400 , message = "Bad Request" )})
58+ @ PostMapping (path = "/create" , produces = APPLICATION_JSON_VALUE )
6159 @ PreAuthorize ("hasRole('ROLE_USER')" )
62- @ Transactional
60+ @ Deprecated // use POST /data/clans instead (with a founder in relationships)
6361 public Map <String , Serializable > createClan (@ RequestParam (value = "name" ) String name ,
6462 @ 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 );
69- return ImmutableMap .of ("id" , clan .getId (), "type" , "clan" );
63+ @ RequestParam (value = "description" , required = false ) String description ) {
64+ Clan clan = clanService .create (name , tag , description );
65+ return Map .of ("id" , clan .getId (), "type" , "clan" );
7066 }
7167
7268 @ ApiOperation ("Generate invitation link" )
7369 @ 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 )
70+ @ ApiResponse (code = 200 , message = "Success with JSON { jwtToken: ? }" ),
71+ @ ApiResponse (code = 400 , message = "Bad Request" )})
72+ @ GetMapping (path = "/generateInvitationLink" , produces = APPLICATION_JSON_VALUE )
7973 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 );
85- return ImmutableMap .of ("jwtToken" , jwtToken );
74+ @ RequestParam (value = "clanId" ) int clanId ,
75+ @ RequestParam (value = "playerId" ) int newMemberId ) {
76+ String jwtToken = clanService .generatePlayerInvitationToken (newMemberId , clanId );
77+ return Map .of ("jwtToken" , jwtToken );
8678 }
8779
88- @ ApiOperation ("Check invitation link and add Member to Clan" )
89- @ RequestMapping (path = "/joinClan" ,
90- method = RequestMethod .POST ,
91- produces = APPLICATION_JSON_UTF8_VALUE )
92- @ Transactional
93- public void joinClan (
94- @ RequestParam (value = "token" ) String stringToken ,
95- Authentication authentication ) throws IOException {
96- clanService .acceptPlayerInvitationToken (stringToken , authentication );
80+ @ ApiOperation ("Check invitation link and add member to Clan" )
81+ @ PostMapping (path = "/joinClan" , produces = APPLICATION_JSON_VALUE )
82+ public void joinClan (@ RequestParam (value = "token" ) String stringToken ) {
83+ clanService .acceptPlayerInvitationToken (stringToken );
9784 }
9885}
0 commit comments