Skip to content

Commit 1292b21

Browse files
committed
More @requiredargsconstructor, more records, fix HashSets
1 parent 29033e8 commit 1292b21

7 files changed

Lines changed: 23 additions & 44 deletions

File tree

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.faforever.api.mautic;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import lombok.RequiredArgsConstructor;
5+
import org.jetbrains.annotations.NotNull;
46
import org.springframework.http.client.ClientHttpResponse;
57
import org.springframework.stereotype.Component;
68
import org.springframework.web.client.DefaultResponseErrorHandler;
@@ -9,19 +11,16 @@
911
import java.io.InputStream;
1012

1113
@Component
14+
@RequiredArgsConstructor
1215
public class MauticApiErrorHandler extends DefaultResponseErrorHandler {
1316

1417
private final ObjectMapper objectMapper;
1518

16-
public MauticApiErrorHandler(ObjectMapper objectMapper) {
17-
this.objectMapper = objectMapper;
18-
}
19-
2019
@Override
21-
public void handleError(ClientHttpResponse response) throws IOException {
20+
public void handleError(@NotNull ClientHttpResponse response) throws IOException {
2221
try (InputStream inputStream = response.getBody()) {
2322
MauticErrorResponse errorResponse = objectMapper.readValue(inputStream, MauticErrorResponse.class);
24-
throw new MauticApiException(errorResponse.getErrors());
23+
throw new MauticApiException(errorResponse.errors());
2524
}
2625
}
2726
}
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
package com.faforever.api.mautic;
22

3-
import lombok.Data;
4-
import lombok.ToString;
5-
63
import java.util.List;
74
import java.util.Map;
85

9-
@Data
10-
public class MauticErrorResponse {
11-
private List<Error> errors;
6+
record MauticErrorResponse(List<Error> errors) {
127

13-
@Data
14-
@ToString
15-
public static class Error {
16-
private int code;
17-
private String message;
18-
private Map<String, Object> details;
8+
static record Error(
9+
int code,
10+
String message,
11+
Map<String, Object> details
12+
) {
1913
}
2014
}

src/main/java/com/faforever/api/mod/ModService.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.faforever.commons.io.Unzipper;
1616
import com.faforever.commons.mod.ModReader;
1717
import com.google.common.primitives.Ints;
18+
import lombok.RequiredArgsConstructor;
1819
import lombok.SneakyThrows;
1920
import lombok.extern.slf4j.Slf4j;
2021
import org.apache.commons.io.FileUtils;
@@ -44,6 +45,7 @@
4445

4546
@Service
4647
@Slf4j
48+
@RequiredArgsConstructor
4749
public class ModService {
4850

4951
/** Legacy path prefix put in front of every mod file. This should be eliminated ASAP. */
@@ -52,12 +54,6 @@ public class ModService {
5254
private final ModRepository modRepository;
5355
private final ModVersionRepository modVersionRepository;
5456

55-
public ModService(FafApiProperties properties, ModRepository modRepository, ModVersionRepository modVersionRepository) {
56-
this.properties = properties;
57-
this.modRepository = modRepository;
58-
this.modVersionRepository = modVersionRepository;
59-
}
60-
6157
@SneakyThrows
6258
@Transactional
6359
@CacheEvict(value = {Mod.TYPE_NAME, ModVersion.TYPE_NAME}, allEntries = true)

src/main/java/com/faforever/api/mod/ModsController.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.faforever.api.player.PlayerService;
88
import com.google.common.io.Files;
99
import io.swagger.annotations.ApiOperation;
10+
import lombok.RequiredArgsConstructor;
1011
import org.springframework.security.core.Authentication;
1112
import org.springframework.web.bind.annotation.RequestMapping;
1213
import org.springframework.web.bind.annotation.RequestMethod;
@@ -21,18 +22,13 @@
2122

2223
@RestController
2324
@RequestMapping(path = "/mods")
25+
@RequiredArgsConstructor
2426
public class ModsController {
2527

2628
private final PlayerService playerService;
2729
private final ModService modService;
2830
private final FafApiProperties fafApiProperties;
2931

30-
public ModsController(PlayerService playerService, ModService modService, FafApiProperties fafApiProperties) {
31-
this.playerService = playerService;
32-
this.modService = modService;
33-
this.fafApiProperties = fafApiProperties;
34-
}
35-
3632
@ApiOperation("Upload a mod")
3733
@RequestMapping(path = "/upload", method = RequestMethod.POST, produces = APPLICATION_JSON_UTF8_VALUE)
3834
public void uploadMod(@RequestParam("file") MultipartFile file, Authentication authentication) throws IOException {

src/main/java/com/faforever/api/user/MeController.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.swagger.annotations.ApiOperation;
1111
import io.swagger.annotations.ApiResponse;
1212
import lombok.Builder;
13+
import lombok.RequiredArgsConstructor;
1314
import lombok.Value;
1415
import org.springframework.security.access.annotation.Secured;
1516
import org.springframework.security.core.GrantedAuthority;
@@ -27,13 +28,10 @@
2728
* Provides the route {@code /me} which returns the currently logged in user's information.
2829
*/
2930
@RestController
31+
@RequiredArgsConstructor
3032
public class MeController {
3133
private final PlayerService playerService;
3234

33-
public MeController(PlayerService playerService) {
34-
this.playerService = playerService;
35-
}
36-
3735
@RequestMapping(method = RequestMethod.GET, value = "/me")
3836
@ApiOperation("Returns the authentication object of the current user")
3937
@ApiResponse(code = 200, message = "Success with JsonApi compliant MeResult")

src/main/java/com/faforever/api/voting/VotingService.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.faforever.api.error.Error;
1111
import com.faforever.api.error.ErrorCode;
1212
import com.faforever.api.game.GamePlayerStatsRepository;
13+
import lombok.RequiredArgsConstructor;
1314
import org.springframework.stereotype.Service;
1415
import org.springframework.util.Assert;
1516

@@ -22,19 +23,13 @@
2223
import java.util.Set;
2324

2425
@Service
26+
@RequiredArgsConstructor
2527
public class VotingService {
2628
private final VoteRepository voteRepository;
2729
private final VotingSubjectRepository votingSubjectRepository;
2830
private final GamePlayerStatsRepository gamePlayerStatsRepository;
2931
private final VotingChoiceRepository votingChoiceRepository;
3032

31-
public VotingService(VoteRepository voteRepository, VotingSubjectRepository votingSubjectRepository, GamePlayerStatsRepository gamePlayerStatsRepository, VotingChoiceRepository votingChoiceRepository) {
32-
this.voteRepository = voteRepository;
33-
this.votingSubjectRepository = votingSubjectRepository;
34-
this.gamePlayerStatsRepository = gamePlayerStatsRepository;
35-
this.votingChoiceRepository = votingChoiceRepository;
36-
}
37-
3833
@Transactional
3934
public void saveVote(Vote vote, Player player) {
4035
vote.setPlayer(player);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.springframework.context.support.MessageSourceAccessor;
1616

1717
import java.time.OffsetDateTime;
18+
import java.util.HashSet;
1819
import java.util.List;
1920
import java.util.Set;
2021

@@ -308,20 +309,20 @@ private void addAnswerToChoice(VotingChoice votingChoice, VotingQuestion votingQ
308309
if (vote.getVotingAnswers() != null) {
309310
vote.getVotingAnswers().add(votingAnswer);
310311
} else {
311-
vote.setVotingAnswers(Set.of(votingAnswer));
312+
vote.setVotingAnswers(new HashSet<>(Set.of(votingAnswer)));
312313
}
313314

314315
if (votingChoice != null) {
315316
if (votingChoice.getVotingAnswers() != null) {
316317
votingChoice.getVotingAnswers().add(votingAnswer);
317318
} else {
318-
votingChoice.setVotingAnswers(Set.of(votingAnswer));
319+
votingChoice.setVotingAnswers(new HashSet<>(Set.of(votingAnswer)));
319320
}
320321

321322
if (votingQuestion.getVotingChoices() != null) {
322323
votingQuestion.getVotingChoices().add(votingChoice);
323324
} else {
324-
votingQuestion.setVotingChoices(Set.of(votingChoice));
325+
votingQuestion.setVotingChoices(new HashSet<>(Set.of(votingChoice)));
325326
}
326327
}
327328
}

0 commit comments

Comments
 (0)