Skip to content

Commit

Permalink
Merge pull request #455 from SWM-NM/dev
Browse files Browse the repository at this point in the history
[REFACTOR] 테스트 종료 결과에 레이팅 정보 추가
  • Loading branch information
aj4941 authored Oct 16, 2023
2 parents 3572a1f + 4c67c54 commit 397dd12
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -28,7 +29,7 @@ public class TestExitController {
private final SaveCodeService saveCodeService;
@PostMapping("/exit")
@Operation(summary = "테스트 종료하기", description = "테스트를 종료할 경우 문제별 정답 여부와 소요 시간을 제공합니다.")
public ResponseEntity<List<AttemptProblemDto>> saveAttemptedProblemResult(@RequestBody TestCheckDto testCheckDto) {
public ResponseEntity<TestResultDto> saveAttemptedProblemResult(@RequestBody TestCheckDto testCheckDto) {
return new ResponseEntity<>(testExitService.testExit(testCheckDto), HttpStatus.OK);
}
@PostMapping("/submit")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<AttemptProblemDto> attemptProblemDtos;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,7 +46,7 @@ public class TestExitService {
private final SolvedCheckService solvedCheckService;

//Controller에서 사용되는 것
public List<AttemptProblemDto> testExit(TestCheckDto testCheckDto)
public TestResultDto testExit(TestCheckDto testCheckDto)
{
Long memberId = SecurityUtils.getCurrentMemberId();
Member member = memberRepository.findById(memberId)
Expand All @@ -54,15 +55,16 @@ public List<AttemptProblemDto> 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<AttemptProblemDto> 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<AttemptProblem> attemptProblems = attemptProblemRepository.findAttemptProblemsByTest_TestId(test.getTestId());

Expand All @@ -73,11 +75,14 @@ public List<AttemptProblemDto> 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<AttemptProblem> attemptProblems = attemptProblemRepository.findAllByTest_TestId(test.getTestId());
long correct = attemptProblems.stream()
Expand All @@ -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);
Expand Down

0 comments on commit 397dd12

Please sign in to comment.