Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(*): 결과 제출 API 구현 #59

Merged
merged 15 commits into from
Aug 10, 2024
Merged

Conversation

morenow98
Copy link
Member

@morenow98 morenow98 commented Aug 9, 2024

PR 변경된 내용

Learning, ProblemSolving Entity 구현

  • Learning과 ProblemSolving을 1대다 관계로 매핑
  • Learning에서 ProblemSolving을 참조하지 않도록 했으며 추후 필요할 시 추가
  • ProblemSolving Entity를 생성할 때 필요한 채점 결과를 위해 Problem Entity에 채점하는 메소드를 추가

결과 제출 API 구현

  • API 명세에 맞춰 Request dto 변경
  • Request dto에 Valid 어노테이션 활용 및 이 검증에 대한 테스트 코드 구현
    • EnumValid 어노테이션 활용해서 LearningMode 검증
  • 푼 문제 리스트와 고른 선지가 다른 리스트에 저장됨. 이를 해결하기 위해 HashMap을 사용
 // solvedProblems와 request의 choice들을 매핑하기 위해 HashMap 사용
Map<Long, Integer> problemIdToChoice = request.problems().stream()
        .collect(Collectors.toMap(
                ProblemResultRequest::problemId,
                ProblemResultRequest::choice
        ));
List<ProblemSolving> problemSolvings = solvedProblems.stream()
        .map(problem -> ProblemSolving.of(
                member,
                problem,
                learning,
                problemIdToChoice.get(problem.getId()),
                problem.checkAnswer(problemIdToChoice.get(problem.getId()))
        ))
        .toList();
  • 중복된 문제를 풀었을 경우 예외처리
if (request.problems().stream().distinct().count() != request.problems().size()) {
    throw new ProblemBusinessException(ProblemErrorCode.DUPLICATED_SOLVING_PROBLEM);
}

추가 내용

  • 문제 id로 조회 시 중복된 id가 요청되면 중복 제거 후 응답 & 테스트 코드 추가
List<Long> problemIds = request.problemIds()
        .stream()
        .distinct()
        .toList();
  • 문제 세트 조회 시 중복된 subject id가 요청되면 중복 제거 후 응답 & 테스트 코드 추가
List<ProblemWithBookmarkDetailQueryDto> problemWithBookmarkDetailQueryDtos = subjectIds.stream()
        .distinct()
        ...

참조

Closes #58

@morenow98 morenow98 self-assigned this Aug 9, 2024
Comment on lines 41 to 45
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new MemberBusinessException(MemberErrorCode.MEMBER_NOT_FOUND));

Certificate certificate = certificateRepository.findById(request.certificateId())
.orElseThrow(() -> new CertificateBusinessException(CertificateErrorCode.CERTIFICATE_NOT_FOUND));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getReferenceById를 안쓰고 여기선 find를 쓰네 #9 여기서 말한 거랑 다른듯?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정해서 올릴게

Comment on lines 63 to 68
List<ProblemSolving> problemSolvings = new ArrayList<>();
for (int i = 0; i < solvedProblems.size(); i++) {
boolean isCorrect = solvedProblems.get(i).checkAnswer(request.problems().get(i).choice());
ProblemSolving problemSolving = ProblemSolving.of(member, solvedProblems.get(i), learning, request.problems().get(i).choice(), isCorrect);
problemSolvings.add(problemSolving);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 이 부분에서 스트림과 람다를 안쓴 이유가 뭐야 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다른 두 리스트를 인덱스로 처리해야 한다고 생각했는데 수정해야 함 수정해서 올릴게

Comment on lines 11 to 8
Long learningTime,
LearningMode learningMode,
ProblemResultRequest problems
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LearningMode 맵핑이 안되면 어떤 예외가 발생하는지? Controller에 대한 테스트코드가 없네 해당 DTO 테스트 코드도 없고
내가 전에 OAuth 할떄 Enum값에 대한 예외 처리를 위해 @EnumValid 만들었는데 이거 써도 될듯?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정해서 올렸으

@morenow98 morenow98 merged commit b3f7840 into develop Aug 10, 2024
1 check passed
@morenow98 morenow98 deleted the feature/58-submit-learning branch September 6, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

결과 제출 API
2 participants