Skip to content

Commit

Permalink
refactor: 코드 정리
Browse files Browse the repository at this point in the history
- 기능과 다른 uri 및 변수명 변경
  • Loading branch information
yechan-kim committed Nov 24, 2024
1 parent 88bc2d2 commit 7028e37
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import com.dpbr.dpbrbe.domain.character.presentation.dto.response.CharacterAverageResponse;
import com.dpbr.dpbrbe.domain.character.presentation.dto.response.CharacterInfoResponse;
import com.dpbr.dpbrbe.domain.character.presentation.dto.response.CharacterRankingResponse;
import com.dpbr.dpbrbe.domain.character.presentation.dto.response.CharacterSearchResponse;
import com.dpbr.dpbrbe.domain.character.presentation.dto.response.CharacterDetailInfoResponse;
import com.dpbr.dpbrbe.domain.character.usecase.AverageStatisticsService;
import com.dpbr.dpbrbe.domain.character.usecase.RankService;
import com.dpbr.dpbrbe.domain.character.usecase.SearchService;
import com.dpbr.dpbrbe.domain.character.usecase.DetailInfoService;
import com.dpbr.dpbrbe.domain.character.usecase.UpdateInfoService;
import com.dpbr.dpbrbe.global.error.ErrorResponse;
import com.dpbr.dpbrbe.global.response.GlobalResponseDto;
Expand All @@ -37,7 +37,7 @@
public class CharacterController {

private final RankService rankService;
private final SearchService searchService;
private final DetailInfoService detailInfoService;
private final UpdateInfoService updateInfoService;
private final AverageStatisticsService averageStatisticsService;

Expand All @@ -55,18 +55,18 @@ public ResponseEntity<GlobalResponseDto<SuccessCode>> saveCharacter(UpdateReques
.body(GlobalResponseDto.success(updateInfoService.execute(request)));
}

@Operation(summary = "캐릭터 검색", description = "사용자 캐릭터의 정보를 검색합니다.")
@Operation(summary = "캐릭터 상세정보", description = "캐릭터의 상세 정보를 호출합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "401", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping("/search")
public ResponseEntity<GlobalResponseDto<CharacterSearchResponse>> SearchCharacter(SearchRequest request) {
@GetMapping("/info")
public ResponseEntity<GlobalResponseDto<CharacterDetailInfoResponse>> CharacterDetailInfo(SearchRequest request) {
return ResponseEntity.status(HttpStatus.OK)
.body(GlobalResponseDto.success(searchService.execute(request), SuccessCode.SUCCESS));
.body(GlobalResponseDto.success(detailInfoService.execute(request), SuccessCode.SUCCESS));
}

@Operation(summary = "캐릭터 레벨 랭킹", description = "전체 캐릭터의 레벨 순위를 호출합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import lombok.Builder;

@Builder
public record CharacterSearchResponse(
public record CharacterDetailInfoResponse(
CharacterInfoResponse info,
Integer sameWorldCharacterCount,
Integer sameJobCharacterCount,
BigDecimal levelPercentage,
BigDecimal unionPercentage,
BigDecimal combatPowerPercentage
) {
public static CharacterSearchResponse of(CharacterInfoResponse info, Integer sameWorldCharacterCount, Integer sameJobCharacterCount,
public static CharacterDetailInfoResponse of(CharacterInfoResponse info, Integer sameWorldCharacterCount, Integer sameJobCharacterCount,
BigDecimal levelPercentage, BigDecimal unionPercentage, BigDecimal combatPowerPercentage) {
return CharacterSearchResponse.builder()
return CharacterDetailInfoResponse.builder()
.info(info)
.sameWorldCharacterCount(sameWorldCharacterCount)
.sameJobCharacterCount(sameJobCharacterCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,45 @@
import com.dpbr.dpbrbe.domain.character.presentation.dto.request.SearchRequest;
import com.dpbr.dpbrbe.domain.character.presentation.dto.response.CharacterInfoResponse;
import com.dpbr.dpbrbe.domain.character.presentation.dto.response.CharacterRankingResponse;
import com.dpbr.dpbrbe.domain.character.presentation.dto.response.CharacterSearchResponse;
import com.dpbr.dpbrbe.domain.character.presentation.dto.response.CharacterDetailInfoResponse;

import lombok.AllArgsConstructor;

@Service
@AllArgsConstructor
public class SearchService {
public class DetailInfoService {

private final RankService rankService;
private final CharacterRepository characterRepository;

public CharacterSearchResponse execute(SearchRequest request) {
public CharacterDetailInfoResponse execute(SearchRequest request) {
// 캐릭터 정보 조회
Character character = characterRepository.findByName(request.name())
.orElseThrow(CharacterNotFoundException::new);

// 동일 월드, 직업 캐릭터 수 조회
Integer sameWorldCharacterCount = characterRepository.countByWorld(character.getWorld());
Integer sameJobCharacterCount = characterRepository.countByJob(character.getJob());

// 레벨 상위 몇 %인지 조회
List<CharacterRankingResponse> levelRanking = rankService.level();
BigDecimal levelPercentage = calculatePercentage(levelRanking, character.getName());

// 유니온 레벨 상위 몇 %인지 조회
List<CharacterRankingResponse> unionRanking = rankService.unionLevel();
BigDecimal unionPercentage = calculatePercentage(unionRanking, character.getName());

// 전투력 상위 몇 %인지 조회
List<CharacterRankingResponse> combatPowerRanking = rankService.combatPower();
BigDecimal combatPowerPercentage = calculatePercentage(combatPowerRanking, character.getName());

return CharacterSearchResponse.of(CharacterInfoResponse.from(character), sameWorldCharacterCount,
// 응답 생성
return CharacterDetailInfoResponse.of(CharacterInfoResponse.from(character), sameWorldCharacterCount,
sameJobCharacterCount,
levelPercentage, unionPercentage, combatPowerPercentage);
}

// 상위 몇 %인지 계산
private BigDecimal calculatePercentage(List<CharacterRankingResponse> rankings, String characterName) {
return rankings.stream()
.filter(ranking -> ranking.info().name().equals(characterName))
Expand Down

0 comments on commit 7028e37

Please sign in to comment.