Skip to content

Commit

Permalink
fix: 순위가 부분에 상관없이 동일하게 반환되는 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
yechan-kim committed Nov 23, 2024
1 parent 5373e46 commit 44173f3
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.dpbr.dpbrbe.domain.character.usecase;

import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

import org.springframework.stereotype.Service;

import com.dpbr.dpbrbe.domain.character.domain.Character;
import com.dpbr.dpbrbe.domain.character.domain.repository.CharacterRepository;
import com.dpbr.dpbrbe.domain.character.presentation.dto.response.CharacterInfoResponse;
import com.dpbr.dpbrbe.domain.character.presentation.dto.response.CharacterRankingResponse;
Expand All @@ -17,25 +19,31 @@ public class RankService {
private final CharacterRepository characterRepository;

public List<CharacterRankingResponse> level() {
AtomicLong rank = new AtomicLong(1);

return characterRepository.findAllByOrderByLevelDesc().stream()
.map(character -> CharacterRankingResponse.of(
(long)(characterRepository.findAllByOrderByLevelDesc().indexOf(character) + 1),
rank.getAndIncrement(),
CharacterInfoResponse.from(character)))
.toList();
}

public List<CharacterRankingResponse> combatPower() {
AtomicLong rank = new AtomicLong(1);

return characterRepository.findAllByOrderByCombatPowerDesc().stream()
.map(character -> CharacterRankingResponse.of(
(long)(characterRepository.findAllByOrderByLevelDesc().indexOf(character) + 1),
rank.getAndIncrement(),
CharacterInfoResponse.from(character)))
.toList();
}

public List<CharacterRankingResponse> unionLevel() {
AtomicLong rank = new AtomicLong(1);

return characterRepository.findAllByOrderByUnionLevelDesc().stream()
.map(character -> CharacterRankingResponse.of(
(long)(characterRepository.findAllByOrderByLevelDesc().indexOf(character) + 1),
rank.getAndIncrement(),
CharacterInfoResponse.from(character)))
.toList();
}
Expand Down

0 comments on commit 44173f3

Please sign in to comment.