Skip to content

Commit 3801f1d

Browse files
committed
Code cleanup related to clans
1 parent b02e3f3 commit 3801f1d

7 files changed

Lines changed: 25 additions & 29 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ before_install:
2525
install:
2626
- git clone https://github.com/FAForever/faf-stack.git faf-stack
2727
&& pushd faf-stack
28-
&& git checkout 79c5d9d
28+
&& git checkout 9f01fbe
2929
&& cp -r config.template config
3030
&& cp .env.template .env
3131
&& ./scripts/init-db.sh

src/inttest/java/com/faforever/api/clan/ClanControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,6 @@ public void createSecondClan() throws Exception {
180180
.andExpect(status().isUnprocessableEntity())
181181
.andReturn();
182182

183-
assertApiError(result, ErrorCode.CLAN_CREATE_CREATOR_IS_IN_A_CLAN);
183+
assertApiError(result, ErrorCode.CLAN_CREATE_FOUNDER_IS_IN_A_CLAN);
184184
}
185185
}

src/main/java/com/faforever/api/clan/ClanService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ClanService {
4040
@SneakyThrows
4141
Clan create(String name, String tag, String description, Player creator) {
4242
if (creator.getClanMembership() != null) {
43-
throw new ApiException(new Error(ErrorCode.CLAN_CREATE_CREATOR_IS_IN_A_CLAN));
43+
throw new ApiException(new Error(ErrorCode.CLAN_CREATE_FOUNDER_IS_IN_A_CLAN));
4444
}
4545
if (clanRepository.findOneByName(name).isPresent()) {
4646
throw new ApiException(new Error(ErrorCode.CLAN_NAME_EXISTS, name));

src/main/java/com/faforever/api/clan/ClansController.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
import org.springframework.security.access.prepost.PreAuthorize;
1515
import org.springframework.security.core.Authentication;
1616
import org.springframework.transaction.annotation.Transactional;
17+
import org.springframework.web.bind.annotation.GetMapping;
18+
import org.springframework.web.bind.annotation.PostMapping;
1719
import org.springframework.web.bind.annotation.RequestMapping;
18-
import org.springframework.web.bind.annotation.RequestMethod;
1920
import org.springframework.web.bind.annotation.RequestParam;
2021
import org.springframework.web.bind.annotation.RestController;
2122

2223
import java.io.IOException;
2324
import java.io.Serializable;
2425
import java.util.Map;
2526

26-
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;
27+
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
2728

2829

2930
@RestController
@@ -37,9 +38,9 @@ public class ClansController {
3738

3839
@ApiOperation("Grab data about yourself and the clan")
3940
@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)
41+
@ApiResponse(code = 200, message = "Success with JSON { player: {id: ?, login: ?}, clan: { id: ?, name: ?, tag: ?}}"),
42+
@ApiResponse(code = 400, message = "Bad Request")})
43+
@GetMapping(path = "/me", produces = APPLICATION_JSON_VALUE)
4344
public MeResult me(Authentication authentication) {
4445
Player player = playerService.getPlayer(authentication);
4546

@@ -55,9 +56,9 @@ public MeResult me(Authentication authentication) {
5556
// a: the new clan with the leader membership, b: the leader membership with the new clan
5657
@ApiOperation("Create a clan with correct leader, founder and clan membership")
5758
@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)
59+
@ApiResponse(code = 200, message = "Success with JSON { id: ?, type: 'clan'}"),
60+
@ApiResponse(code = 400, message = "Bad Request")})
61+
@PostMapping(path = "/create", produces = APPLICATION_JSON_VALUE)
6162
@PreAuthorize("hasRole('ROLE_USER')")
6263
@Transactional
6364
public Map<String, Serializable> createClan(@RequestParam(value = "name") String name,
@@ -71,28 +72,24 @@ public Map<String, Serializable> createClan(@RequestParam(value = "name") String
7172

7273
@ApiOperation("Generate invitation link")
7374
@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)
75+
@ApiResponse(code = 200, message = "Success with JSON { jwtToken: ? }"),
76+
@ApiResponse(code = 400, message = "Bad Request")})
77+
@GetMapping(path = "/generateInvitationLink", produces = APPLICATION_JSON_VALUE)
7978
public Map<String, Serializable> generateInvitationLink(
80-
@RequestParam(value = "clanId") int clanId,
81-
@RequestParam(value = "playerId") int newMemberId,
82-
Authentication authentication) throws IOException {
79+
@RequestParam(value = "clanId") int clanId,
80+
@RequestParam(value = "playerId") int newMemberId,
81+
Authentication authentication) throws IOException {
8382
Player player = playerService.getPlayer(authentication);
8483
String jwtToken = clanService.generatePlayerInvitationToken(player, newMemberId, clanId);
8584
return ImmutableMap.of("jwtToken", jwtToken);
8685
}
8786

8887
@ApiOperation("Check invitation link and add Member to Clan")
89-
@RequestMapping(path = "/joinClan",
90-
method = RequestMethod.POST,
91-
produces = APPLICATION_JSON_UTF8_VALUE)
88+
@PostMapping(path = "/joinClan", produces = APPLICATION_JSON_VALUE)
9289
@Transactional
9390
public void joinClan(
94-
@RequestParam(value = "token") String stringToken,
95-
Authentication authentication) throws IOException {
91+
@RequestParam(value = "token") String stringToken,
92+
Authentication authentication) throws IOException {
9693
clanService.acceptPlayerInvitationToken(stringToken, authentication);
9794
}
9895
}

src/main/java/com/faforever/api/error/ErrorCode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public enum ErrorCode {
5555
INVALID_METADATA(146, "Invalid metadata", "Metadata is not valid: {0}"),
5656
MAP_RENAME_FAILED(147, "Cannot rename to correct name failed ", "Cannot rename file ''{0}''"),
5757
MAP_INVALID_ZIP(148, "Invalid zip file", "The zip file should only contain one folder at the root level"),
58-
CLAN_CREATE_CREATOR_IS_IN_A_CLAN(149, "You are already in a clan", "Clan creator is already member of a clan"),
58+
CLAN_CREATE_FOUNDER_IS_IN_A_CLAN(149, "You are already in a clan", "Clan founder is already member of a clan"),
5959
CLAN_ACCEPT_TOKEN_EXPIRE(150, "Token Expire", "The Invitation Link expire"),
6060
CLAN_ACCEPT_WRONG_PLAYER(151, "Wrong Player", "Your are not the invited player"),
6161
CLAN_ACCEPT_PLAYER_IN_A_CLAN(152, "Player is in a clan", "You are already in a clan"),

src/test/java/com/faforever/api/clan/ClanServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void createClanWhereLeaderIsAlreadyInAClan() {
7171
instance.create(clanName, tag, description, creator);
7272
fail();
7373
} catch (ApiException e) {
74-
assertThat(e, hasErrorCode(ErrorCode.CLAN_CREATE_CREATOR_IS_IN_A_CLAN));
74+
assertThat(e, hasErrorCode(ErrorCode.CLAN_CREATE_FOUNDER_IS_IN_A_CLAN));
7575
}
7676
verify(clanRepository, Mockito.never()).save(any(Clan.class));
7777
}

src/test/java/com/faforever/api/data/listeners/ClanEnricherListenerTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
public class ClanEnricherListenerTest {
1313
private ClanEnricherListener instance;
1414

15-
1615
@BeforeEach
17-
public void setUp() throws Exception {
16+
void setUp() throws Exception {
1817
instance = new ClanEnricherListener();
1918

2019
FafApiProperties fafApiProperties = new FafApiProperties();
@@ -24,7 +23,7 @@ public void setUp() throws Exception {
2423
}
2524

2625
@Test
27-
public void enrich() throws Exception {
26+
void enrich() throws Exception {
2827
Clan clan = ClanFactory.builder().id(54).build();
2928

3029
instance.enrich(clan);

0 commit comments

Comments
 (0)