diff --git a/src/main/java/swm_nm/morandi/domain/testExit/controller/TestExitController.java b/src/main/java/swm_nm/morandi/domain/testExit/controller/TestExitController.java index b12fc54a..9bbb2728 100644 --- a/src/main/java/swm_nm/morandi/domain/testExit/controller/TestExitController.java +++ b/src/main/java/swm_nm/morandi/domain/testExit/controller/TestExitController.java @@ -12,6 +12,7 @@ import swm_nm.morandi.domain.testDuring.dto.TestCheckDto; import swm_nm.morandi.domain.testExit.dto.AttemptCodeDto; import swm_nm.morandi.domain.testExit.dto.AttemptProblemDto; +import swm_nm.morandi.domain.testExit.dto.TestResultDto; import swm_nm.morandi.domain.testExit.service.SaveCodeService; import swm_nm.morandi.domain.testExit.service.TestExitService; @@ -28,7 +29,7 @@ public class TestExitController { private final SaveCodeService saveCodeService; @PostMapping("/exit") @Operation(summary = "테스트 종료하기", description = "테스트를 종료할 경우 문제별 정답 여부와 소요 시간을 제공합니다.") - public ResponseEntity> saveAttemptedProblemResult(@RequestBody TestCheckDto testCheckDto) { + public ResponseEntity saveAttemptedProblemResult(@RequestBody TestCheckDto testCheckDto) { return new ResponseEntity<>(testExitService.testExit(testCheckDto), HttpStatus.OK); } @PostMapping("/submit") diff --git a/src/main/java/swm_nm/morandi/domain/testExit/dto/TestResultDto.java b/src/main/java/swm_nm/morandi/domain/testExit/dto/TestResultDto.java index 8ecdb6d1..abeb6dd4 100644 --- a/src/main/java/swm_nm/morandi/domain/testExit/dto/TestResultDto.java +++ b/src/main/java/swm_nm/morandi/domain/testExit/dto/TestResultDto.java @@ -1,5 +1,10 @@ package swm_nm.morandi.domain.testExit.dto; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import lombok.*; import java.time.LocalDateTime; @@ -11,6 +16,12 @@ @NoArgsConstructor @AllArgsConstructor public class TestResultDto { + + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonDeserialize(using = LocalDateTimeDeserializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime testDate; + private Long beforeRating; + private Long afterRating; private List attemptProblemDtos; } diff --git a/src/main/java/swm_nm/morandi/domain/testExit/service/CalculateRatingService.java b/src/main/java/swm_nm/morandi/domain/testExit/service/CalculateRatingService.java index 0c503f4d..41bdbc3e 100644 --- a/src/main/java/swm_nm/morandi/domain/testExit/service/CalculateRatingService.java +++ b/src/main/java/swm_nm/morandi/domain/testExit/service/CalculateRatingService.java @@ -48,11 +48,9 @@ public Long calculateTestRating(Member member, Tests test) { } rating = (addRating == 0) ? 500L : rating + addRating; long resultRating = (memberRating * 4 + rating) / 5; // 사용자 현재 레이팅 반영 - if (allSolved) memberRating = max(memberRating, resultRating); - else memberRating = resultRating; - member.setRating(memberRating); + if (allSolved) resultRating = max(memberRating, resultRating); test.setOriginRating(rating); // 순수 테스트 레이팅 결과 - return memberRating; + return resultRating; } private static long getRating(Integer problemCount) { long rating = 0L; diff --git a/src/main/java/swm_nm/morandi/domain/testExit/service/TestExitService.java b/src/main/java/swm_nm/morandi/domain/testExit/service/TestExitService.java index 860b59d1..f324386d 100644 --- a/src/main/java/swm_nm/morandi/domain/testExit/service/TestExitService.java +++ b/src/main/java/swm_nm/morandi/domain/testExit/service/TestExitService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; import swm_nm.morandi.domain.testDuring.dto.TestCheckDto; import swm_nm.morandi.domain.testDuring.dto.TestStatus; +import swm_nm.morandi.domain.testExit.dto.TestResultDto; import swm_nm.morandi.domain.testInfo.entity.AttemptProblem; import swm_nm.morandi.domain.testInfo.entity.TestType; import swm_nm.morandi.domain.testInfo.entity.Tests; @@ -45,7 +46,7 @@ public class TestExitService { private final SolvedCheckService solvedCheckService; //Controller에서 사용되는 것 - public List testExit(TestCheckDto testCheckDto) + public TestResultDto testExit(TestCheckDto testCheckDto) { Long memberId = SecurityUtils.getCurrentMemberId(); Member member = memberRepository.findById(memberId) @@ -54,15 +55,16 @@ public List testExit(TestCheckDto testCheckDto) .orElseThrow(() -> new MorandiException(TestErrorCode.TEST_NOT_FOUND)); TestType testType = testTypeRepository.findTestTypeByTestTypename(test.getTestTypename()) .orElseThrow(() -> new MorandiException(TestTypeErrorCode.TEST_TYPE_NOT_FOUND)); - return testExit(testCheckDto,member,test,testType); + return testExit(testCheckDto, member, test, testType); } @Transactional - public List testExit(TestCheckDto testCheckDto,Member member,Tests test,TestType testType) { + public TestResultDto testExit(TestCheckDto testCheckDto, Member member, Tests test, TestType testType) { String bojId = testCheckDto.getBojId(); solvedCheckService.checkAttemptedProblemResult(test, bojId); - saveTestResult(member,test, testType); + TestResultDto testResultDto = TestResultDto.builder().build(); + saveTestResult(member, test, testType, testResultDto); List attemptProblems = attemptProblemRepository.findAttemptProblemsByTest_TestId(test.getTestId()); @@ -73,11 +75,14 @@ public List testExit(TestCheckDto testCheckDto,Member member, attemptProblemDto.setTestProblemId(number++); attemptProblemDtos.add(attemptProblemDto); } - return attemptProblemDtos; + + testResultDto.setAttemptProblemDtos(attemptProblemDtos); + + return testResultDto; } @Transactional - public void saveTestResult(Member member,Tests test, TestType testType) { + public void saveTestResult(Member member, Tests test, TestType testType, TestResultDto testResultDto) { test.setTestStatus(TestStatus.COMPLETED); List attemptProblems = attemptProblemRepository.findAllByTest_TestId(test.getTestId()); long correct = attemptProblems.stream() @@ -92,6 +97,9 @@ public void saveTestResult(Member member,Tests test, TestType testType) { test.setTestRating(calculateRatingService.calculateTestRating(member, test)); member.setCurrentTestId(-1L); + testResultDto.setBeforeRating(member.getRating()); + testResultDto.setAfterRating(test.getTestRating()); + testResultDto.setTestDate(test.getTestDate()); // 테스트 결과 저장 testTypeRepository.save(testType);