diff --git a/src/main/java/com/mosabulgyeo/bewavoca/service/CharacterService.java b/src/main/java/com/mosabulgyeo/bewavoca/service/CharacterService.java index 648e947..27735df 100644 --- a/src/main/java/com/mosabulgyeo/bewavoca/service/CharacterService.java +++ b/src/main/java/com/mosabulgyeo/bewavoca/service/CharacterService.java @@ -38,18 +38,26 @@ public CharacterService(CharacterRepository characterRepository, UserRepository * @throws IllegalArgumentException 사용자가 존재하지 않을 경우 */ public List getAvailableCharacters(String deviceId) { + // 사용자 확인 User user = userRepository.findByDeviceId(deviceId) .orElseThrow(() -> new IllegalArgumentException("User not found for this device.")); - List availableCharacters = characterRepository.findAll().stream() + // 기본 캐릭터(ID 1번) 조회 + Character defaultCharacter = characterRepository.findById(1L) + .orElseThrow(() -> new IllegalStateException("Default character (ID 1) not found")); + + // 사용자가 클리어한 지역에 따라 잠금 해제된 캐릭터 필터링 + List unlockedCharacters = characterRepository.findAll().stream() .filter(character -> user.hasClearedRegion(character.getRegion().getId())) .collect(Collectors.toList()); - if (availableCharacters.isEmpty()) { - throw new IllegalArgumentException("No available characters for this device."); + // 기본 캐릭터(ID 1번)를 추가 + if (unlockedCharacters.stream().noneMatch(character -> character.getId().equals(defaultCharacter.getId()))) { + unlockedCharacters.add(defaultCharacter); } - return availableCharacters.stream() + // 캐릭터 리스트를 DTO로 변환하여 반환 + return unlockedCharacters.stream() .map(character -> new CharacterResponse( character.getId(), character.getName(), @@ -114,4 +122,4 @@ public CharacterResponse getSelectedCharacter(String deviceId) { character.getRegion().getName() ); } -} \ No newline at end of file +}