Skip to content

Commit

Permalink
Merge pull request #510 from SWM-NM/feat/#509
Browse files Browse the repository at this point in the history
✨ [FEAT] 테스트 시작시 각 문제 정답여부 반환하게 tests API 수정 #509
  • Loading branch information
miiiinju1 authored Oct 24, 2023
2 parents 6600dd3 + dcf08f3 commit ddd3dc2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package swm_nm.morandi.domain.testStart.dto;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
@Builder
@AllArgsConstructor
public class BojProblemDto {
public Long bojProblemId;
public Boolean isSolved;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Builder
public class TestStartResponseDto {
private Long testId;
private List<Long> bojProblemIds = new ArrayList<>();
private List<BojProblemDto> bojProblems = new ArrayList<>();
private List<TestCodeDto> testCodeDtos = new ArrayList<>();
private Long remainingTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import swm_nm.morandi.domain.problem.dto.BojProblem;
import swm_nm.morandi.domain.problem.entity.Problem;
import swm_nm.morandi.domain.testDuring.dto.TempCode;
import swm_nm.morandi.domain.testDuring.service.TempCodeService;
import swm_nm.morandi.domain.testInfo.entity.TestType;
import swm_nm.morandi.domain.testInfo.repository.TestTypeRepository;
import swm_nm.morandi.domain.testStart.dto.BojProblemDto;
import swm_nm.morandi.domain.testStart.dto.TestCodeDto;
import swm_nm.morandi.domain.testStart.dto.TestStartResponseDto;
import swm_nm.morandi.domain.testInfo.entity.AttemptProblem;
Expand Down Expand Up @@ -84,12 +83,20 @@ public TestStartResponseDto getTestStartsData(Long testTypeId) {
return getTestStartResponseDto(test, bojProblems);
}


//테스트 만들어졌을 때에는 모두 안 푼 문제니깐 false로 초기화
private TestStartResponseDto getTestStartResponseDto(Tests test, List<BojProblem> bojProblems) {
List<Long> bojProblemIds = bojProblems.stream().map(BojProblem::getProblemId).collect(Collectors.toList());
List<BojProblemDto> bojProblemDtos = bojProblems.stream().map(bojProblem ->
BojProblemDto.builder()
.isSolved(false)
.bojProblemId(bojProblem.getProblemId())
.build())
.collect(Collectors.toList());

List<TestCodeDto> testCodeDtos = getTestCodeDtos(test);
return TestStartResponseDto.builder()
.testId(test.getTestId())
.bojProblemIds(bojProblemIds)
.bojProblems(bojProblemDtos)
.remainingTime(test.getRemainingTime())
.testCodeDtos(testCodeDtos)
.build();
Expand Down Expand Up @@ -122,13 +129,19 @@ private List<TestCodeDto> getTestCodeDtos(Tests test) {
private TestStartResponseDto getTestStartResponseDto(Tests test) {
Long testId = test.getTestId();
List<AttemptProblem> attemptProblems = attemptProblemRepository.findAttemptProblemsByTest_TestId(testId);
List<Long> bojProblemIds = attemptProblems.stream().map(AttemptProblem::getProblem)
.map(Problem::getBojProblemId).collect(Collectors.toList());

List<BojProblemDto> bojProblemDtos =
attemptProblems.stream().map(attemptProblem -> BojProblemDto.builder()
.isSolved(attemptProblem.getIsSolved())
.bojProblemId(attemptProblem.getProblem().getBojProblemId())
.build()).collect(Collectors.toList());

List<TestCodeDto> testCodeDtos = getTestCodeDtos(test);

TestStartResponseDto testStartResponseDto
= TestStartResponseDto.builder()
.testId(testId)
.bojProblemIds(bojProblemIds)
.bojProblems(bojProblemDtos)
.remainingTime(test.getRemainingTime())
.testCodeDtos(testCodeDtos)
.build();
Expand Down

0 comments on commit ddd3dc2

Please sign in to comment.