-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FIX] 최근 4개 테스트 정보 제공
- Loading branch information
Showing
10 changed files
with
90 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 33 additions & 5 deletions
38
src/main/java/swm_nm/morandi/domain/testInfo/service/LatestTestInfoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,59 @@ | ||
package swm_nm.morandi.domain.testInfo.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import swm_nm.morandi.domain.testExit.dto.AttemptProblemDto; | ||
import swm_nm.morandi.domain.testInfo.entity.AttemptProblem; | ||
import swm_nm.morandi.domain.testRecord.dto.TestRecordDto; | ||
import swm_nm.morandi.domain.testInfo.entity.Tests; | ||
import swm_nm.morandi.domain.testRecord.mapper.TestRecordMapper; | ||
import swm_nm.morandi.domain.testInfo.repository.TestRepository; | ||
import swm_nm.morandi.domain.testRecord.repository.AttemptProblemRepository; | ||
import swm_nm.morandi.global.utils.SecurityUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class LatestTestInfoService { | ||
|
||
private final TestRepository testRepository; | ||
|
||
private final AttemptProblemRepository attemptProblemRepository; | ||
|
||
public List<TestRecordDto> getTestRecordDtosLatest() { | ||
Long memberId = SecurityUtils.getCurrentMemberId(); | ||
Pageable pageable = PageRequest.of(0, 5); | ||
List<Tests> recentTests = testRepository.findAllByMember_MemberIdOrderByTestDateDesc(memberId, pageable); | ||
List<TestRecordDto> testRecordDtos = recentTests.stream().map(TestRecordMapper::convertToDto).collect(Collectors.toList()); | ||
Pageable pageable = PageRequest.of(0, 4); | ||
List<Tests> recentTests = testRepository.findDataRecent4(memberId, pageable); | ||
List<TestRecordDto> testRecordDtos = new ArrayList<>(); | ||
recentTests.forEach(recentTest -> { | ||
List<AttemptProblemDto> attemptProblemDtos = getAttemptProblemDtos(recentTest); | ||
TestRecordDto testRecordDto = TestRecordMapper.convertToDto(recentTest, attemptProblemDtos); | ||
testRecordDtos.add(testRecordDto); | ||
}); | ||
getTestRecordDtos(testRecordDtos); | ||
return testRecordDtos; | ||
} | ||
private List<AttemptProblemDto> getAttemptProblemDtos(Tests test) { | ||
List<AttemptProblemDto> attemptProblemDtos = new ArrayList<>(); | ||
Long testId = test.getTestId(); | ||
List<AttemptProblem> attemptProblems = attemptProblemRepository.findAttemptProblemsByTest_TestId(testId); | ||
long index = 1; | ||
for (AttemptProblem attemptProblem : attemptProblems) { | ||
AttemptProblemDto attemptProblemDto = AttemptProblemDto.getAttemptProblemDto(attemptProblem); | ||
attemptProblemDto.setTestProblemId(index++); | ||
attemptProblemDtos.add(attemptProblemDto); | ||
} | ||
return attemptProblemDtos; | ||
} | ||
|
||
private static void getTestRecordDtos(List<TestRecordDto> testRecordDtos) { | ||
while (testRecordDtos.size() < 4) { | ||
testRecordDtos.add(TestRecordMapper.dummyDto()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 25 additions & 1 deletion
26
src/main/java/swm_nm/morandi/domain/testRecord/mapper/TestRecordMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters