Skip to content

Commit

Permalink
Refactor unit tests and original clan create
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Nov 13, 2019
1 parent fba6a91 commit 75de6d1
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 271 deletions.
1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 3 additions & 24 deletions src/main/java/com/faforever/api/clan/ClanService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.List;

@Service
Expand Down Expand Up @@ -67,35 +66,15 @@ public void preCreate(Clan clan) {
@SneakyThrows
@Transactional
@Deprecated
// use preCreate instead
// use POST via Elide instead
Clan create(String name, String tag, String description) {
Player creator = playerService.getCurrentPlayer();

if (creator.getClanMembership() != null) {
throw ApiException.of(ErrorCode.CLAN_CREATE_FOUNDER_IS_IN_A_CLAN);
}
if (clanRepository.findOneByName(name).isPresent()) {
throw ApiException.of(ErrorCode.CLAN_NAME_EXISTS, name);
}
if (clanRepository.findOneByTag(tag).isPresent()) {
throw ApiException.of(ErrorCode.CLAN_TAG_EXISTS, tag);
}

Clan clan = new Clan();
clan.setName(name);
clan.setTag(tag);
clan.setDescription(description);
clan.setFounder(playerService.getCurrentPlayer());

clan.setFounder(creator);
clan.setLeader(creator);

ClanMembership membership = new ClanMembership();
membership.setClan(clan);
membership.setPlayer(creator);

clan.setMemberships(Collections.singletonList(membership));

// clan membership is saved over cascading, otherwise validation will fail
// validation is done at preCreate() called by ClanListener
clanRepository.save(clan);
return clan;
}
Expand Down
Loading

0 comments on commit 75de6d1

Please sign in to comment.