Skip to content

Commit

Permalink
#53 style: 코드 포맷 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwp031 committed Oct 16, 2023
1 parent 74880c2 commit f0b0741
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
import com.example.ourworldcup.repository.GameRepository;
import com.example.ourworldcup.repository.RoundRepository;
import com.example.ourworldcup.repository.UserAccountRepository;
import com.example.ourworldcup.repository.WorldcupRepository;
import com.example.ourworldcup.repository.item.ItemRepository;
import com.example.ourworldcup.service.game.GameService;
import com.example.ourworldcup.service.item.ItemService;
import com.example.ourworldcup.service.userAccount.UserAccountService;
import com.example.ourworldcup.service.worldcup.WorldcupService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -33,9 +32,9 @@
public class GameServiceImpl implements GameService {
private final RoundRepository roundRepository;
private final UserAccountRepository userAccountRepository;
private final WorldcupRepository worldcupRepository;
private final GameRepository gameRepository;
private final ItemRepository itemRepository;

private final UserAccountService userAccountService;
private final ItemService itemService;
private final WorldcupService worldcupService;

Expand All @@ -47,9 +46,8 @@ public Game createGame(Long userAccountId, Long worldcupId, Long initialRound, P
throw new IllegalArgumentException("해당 initialRound는 올바르지 않습니다.");
}

UserAccount userAccount = userAccountRepository.getReferenceById(userAccountId);
Worldcup worldcup = worldcupRepository.findById(worldcupId)
.orElseThrow(() -> new IllegalArgumentException("월드컵 아이디가 잘못됐습니다."));
UserAccount userAccount = userAccountService.findById(userAccountId);
Worldcup worldcup = worldcupService.findById(worldcupId);

RoundType initialRoundType = RoundType.getRoundType(initialRound);
Game game = Game.builder()
Expand Down Expand Up @@ -128,7 +126,7 @@ public List<Game> findGamesByUserAccountId(Long userAccountId) {
public List<VsResultDto> getVsResults(Long gameId) {
Game source = this.findById(gameId);
List<Game> games = gameRepository.findAll().stream()
.filter(g -> g.getCurrentRoundType().equals(RoundType.ROUND1) && g.getCurrentRoundOrder().equals(g.getNextStageEndRoundOrder()))
.filter(g -> g.getCurrentRoundType().equals(RoundType.ROUND2) && g.getCurrentRoundOrder().equals(g.getNextStageEndRoundOrder()))
.filter(g -> !Objects.equals(g.getId(), gameId))
.toList();
List<VsResultDto> vsResultDtos = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
public class RoundServiceImpl implements RoundService {
private final RoundRepository roundRepository;
private final GameService gameService;

@Override
public Round findById(Long id) {
return roundRepository.findById(id)
Expand Down Expand Up @@ -58,17 +59,17 @@ public Round getRound(Long gameId) {
public List<Round> createNewStageRoundsOnlyIfStageEnded(Game game) {
Long roundNumIdx = 0L;
List<Round> newRounds = new ArrayList<>();
for (long i = game.getCurrentRoundOrder() - game.getCurrentRoundType().getTotalRounds(); i < game.getCurrentRoundOrder(); i+=2) {
for (long i = game.getCurrentRoundOrder() - game.getCurrentRoundType().getTotalRounds(); i < game.getCurrentRoundOrder(); i += 2) {
Long newItem1Num = game.getRounds().get((int) i).getSelectedItem();
Long newItem2Num = game.getRounds().get((int) i+1).getSelectedItem();
Long newItem2Num = game.getRounds().get((int) i + 1).getSelectedItem();
Round newRound = Round.builder()
.worldcup(game.getWorldcup())
.game(game)
.roundNum(game.getCurrentRoundOrder() + roundNumIdx)
.item1(newItem1Num)
.item2(newItem2Num)
.build();
roundNumIdx+=1L;
roundNumIdx += 1L;
roundRepository.save(newRound);
newRounds.add(newRound);
}
Expand All @@ -81,7 +82,7 @@ public void updateGameIfStageEnded(Long gameId) {
if (game.getCurrentRoundOrder().equals(game.getNextStageEndRoundOrder())) {
game.addRounds(createNewStageRoundsOnlyIfStageEnded(game));
game.setCurrentRoundType(RoundType.getNextRoundType(game.getCurrentRoundType()));
game.setNextStageEndRoundOrder(game.getNextStageEndRoundOrder()+game.getCurrentRoundType().getTotalRounds());
game.setNextStageEndRoundOrder(game.getNextStageEndRoundOrder() + game.getCurrentRoundType().getTotalRounds());
return;
}
return;
Expand All @@ -102,7 +103,7 @@ public void setCurrentRoundOrder(Long gameId, Long roundOrder) {
@Override
public Boolean checkFinished(Long gameId) {
Game game = gameService.findById(gameId);
return game.getCurrentRoundType().equals(RoundType.ROUND1);
return game.getCurrentRoundType().equals(RoundType.ROUND2);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,40 @@
import com.example.ourworldcup.repository.UserAccountRoleRepository;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;


@RequiredArgsConstructor
@Transactional
@Service
public class UserAccountServiceImpl implements UserAccountService{
public class UserAccountServiceImpl implements UserAccountService {
private final RoleRepository roleRepository;
private final UserAccountRoleRepository userAccountRoleRepository;
private final AuthorityRepository authorityRepository;
private final UserAccountRepository userAccountRepository;

@Override
public UserAccount findById(Long id) {
return userAccountRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("해당 id를 가진 userAccount가 존재하지 않습니다."));
}

@Transactional
@Override
public void setRoles(UserAccount userAccount, List<RoleType> roles) {
for (RoleType roleType : roles) {
Role role = roleRepository.findByRoleType(roleType);
UserAccountRole userAccountRole = UserAccountRole.builder()
UserAccountRole userAccountRole = UserAccountRole.builder()
.role(role)
.userAccount(userAccount)
.build();
userAccountRoleRepository.save(userAccountRole);
}
}

@Transactional
@Override
public List<Authority> getAuthorities(UserAccount userAccount) {
Expand All @@ -63,12 +68,14 @@ public List<RoleType> getRoleTypes(UserAccount userAccount) {
return getRole(userAccount).stream()
.map(Role::getRoleType).toList();
}

@Override
public List<Role> getRole(UserAccount userAccount) {
List<Role> roles = userAccount.getUserAccountRoles().stream()
.map(UserAccountRole::getRole).toList();
return roles;
}

@Transactional
@Override
public Optional<UserAccount> findByEmailAndAuthProviderType(String email, AuthProviderType authProviderType) {
Expand Down

0 comments on commit f0b0741

Please sign in to comment.