|
16 | 16 | import scanner.history.dto.report.ScanSummaryDto;
|
17 | 17 | import scanner.history.entity.ScanHistory;
|
18 | 18 | import scanner.history.entity.ScanHistoryDetail;
|
19 |
| -import scanner.history.repository.ScanHistoryDetailsRepository; |
20 | 19 | import scanner.history.repository.ScanHistoryRepository;
|
21 | 20 | import scanner.history.dto.report.ReportResponse;
|
22 | 21 |
|
|
27 | 26 | public class ScanHistoryService {
|
28 | 27 |
|
29 | 28 | 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 | + } |
31 | 36 |
|
32 | 37 | public List<ScanHistory> getHistoryList() {
|
33 | 38 | return scanHistoryRepository.findTop10ByOrderByHistorySeqDesc();
|
34 | 39 | }
|
35 | 40 |
|
36 | 41 | @Transactional
|
37 | 42 | 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 | + } |
38 | 48 |
|
39 |
| - ScanHistory history = scanHistoryRepository.findByHistorySeq(reportId) |
| 49 | + private ScanHistory getScanHistory(Long reportId) { |
| 50 | + return scanHistoryRepository.findByHistorySeq(reportId) |
40 | 51 | .orElseThrow(() -> new ApiException(ResponseCode.NO_SCAN_RESULT));
|
| 52 | + } |
41 | 53 |
|
42 |
| - ScanSummaryDto.Content summaryDto = ScanSummaryDto.mapDtoByLanguage(history, lang); |
| 54 | + private ScanSummaryDto.Content createSummaryDto(ScanHistory scanHistory, Language lang) { |
| 55 | + return ScanSummaryDto.mapDtoByLanguage(scanHistory, lang); |
| 56 | + } |
43 | 57 |
|
44 |
| - List<ScanHistoryDetail> details = scanHistoryDetailsRepository.findByHistorySeq(reportId); |
| 58 | + private List<ScanHistoryDetailDto> createDetailsDto(List<ScanHistoryDetail> details, Language lang) { |
45 | 59 | List<ScanHistoryDetailDto> detailsDto;
|
46 |
| - if (lang == Language.KOREAN) |
| 60 | + if (lang == Language.KOREAN) { |
47 | 61 | detailsDto = details.stream().map(ScanHistoryDetailDto::toKor).collect(Collectors.toList());
|
48 |
| - else |
| 62 | + } else { |
49 | 63 | 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; |
60 | 66 | }
|
61 | 67 | }
|
0 commit comments