Skip to content

Commit 7a3b48a

Browse files
committed
refactor: redesign getReportDetails method. (73)
1 parent 58df490 commit 7a3b48a

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/main/java/scanner/history/service/ScanHistoryService.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import scanner.history.dto.report.ScanSummaryDto;
1717
import scanner.history.entity.ScanHistory;
1818
import scanner.history.entity.ScanHistoryDetail;
19-
import scanner.history.repository.ScanHistoryDetailsRepository;
2019
import scanner.history.repository.ScanHistoryRepository;
2120
import scanner.history.dto.report.ReportResponse;
2221

@@ -27,35 +26,42 @@
2726
public class ScanHistoryService {
2827

2928
private final ScanHistoryRepository scanHistoryRepository;
30-
private final ScanHistoryDetailsRepository scanHistoryDetailsRepository;
29+
30+
public VisualDto.Response getVisualization(Long reportId) {
31+
ScanHistory history = scanHistoryRepository.findByHistorySeq(reportId)
32+
.orElseThrow(() -> new ApiException(ResponseCode.NO_SCAN_RESULT));
33+
34+
return new VisualDto.Response(history.getHistorySeq(), history.getCreatedAt(), history.getVisual());
35+
}
3136

3237
public List<ScanHistory> getHistoryList() {
3338
return scanHistoryRepository.findTop10ByOrderByHistorySeqDesc();
3439
}
3540

3641
@Transactional
3742
public ReportResponse getReportDetails(Long reportId, Language lang) {
43+
ScanHistory scanHistory = getScanHistory(reportId);
44+
ScanSummaryDto.Content summaryDto = createSummaryDto(scanHistory, lang);
45+
List<ScanHistoryDetailDto> detailsDto = createDetailsDto(scanHistory.getDetails(), lang);
46+
return new ReportResponse(summaryDto, detailsDto);
47+
}
3848

39-
ScanHistory history = scanHistoryRepository.findByHistorySeq(reportId)
49+
private ScanHistory getScanHistory(Long reportId) {
50+
return scanHistoryRepository.findByHistorySeq(reportId)
4051
.orElseThrow(() -> new ApiException(ResponseCode.NO_SCAN_RESULT));
52+
}
4153

42-
ScanSummaryDto.Content summaryDto = ScanSummaryDto.mapDtoByLanguage(history, lang);
54+
private ScanSummaryDto.Content createSummaryDto(ScanHistory scanHistory, Language lang) {
55+
return ScanSummaryDto.mapDtoByLanguage(scanHistory, lang);
56+
}
4357

44-
List<ScanHistoryDetail> details = scanHistoryDetailsRepository.findByHistorySeq(reportId);
58+
private List<ScanHistoryDetailDto> createDetailsDto(List<ScanHistoryDetail> details, Language lang) {
4559
List<ScanHistoryDetailDto> detailsDto;
46-
if (lang == Language.KOREAN)
60+
if (lang == Language.KOREAN) {
4761
detailsDto = details.stream().map(ScanHistoryDetailDto::toKor).collect(Collectors.toList());
48-
else
62+
} else {
4963
detailsDto = details.stream().map(ScanHistoryDetailDto::toEng).collect(Collectors.toList());
50-
51-
return new ReportResponse(summaryDto, detailsDto);
52-
}
53-
54-
public VisualDto.Response getVisualization(Long reportId) {
55-
56-
ScanHistory history = scanHistoryRepository.findByHistorySeq(reportId)
57-
.orElseThrow(() -> new ApiException(ResponseCode.NO_SCAN_RESULT));
58-
59-
return new VisualDto.Response(history.getHistorySeq(), history.getCreatedAt(), history.getVisual());
64+
}
65+
return detailsDto;
6066
}
6167
}

0 commit comments

Comments
 (0)