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

퀴즈 진행 컨트롤러 전달 인자 수정 #42 #44

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.ripple.BE.learning.dto.QuizDTO;
import com.ripple.BE.learning.dto.QuizListDTO;
import com.ripple.BE.learning.dto.QuizResultDTO;
import com.ripple.BE.learning.dto.request.SubmitAnswerRequest;
import com.ripple.BE.learning.dto.response.QuizListResponse;
import com.ripple.BE.learning.dto.response.QuizResponse;
import com.ripple.BE.learning.dto.response.QuizResultResponse;
Expand All @@ -13,15 +12,16 @@
import com.ripple.BE.user.domain.type.Level;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -47,15 +47,16 @@ public ResponseEntity<ApiResponse<Object>> startQuiz(
.body(ApiResponse.from(QuizListResponse.toQuizListResponse(quizListDTO)));
}

@Operation(summary = "퀴즈 제출", description = "퀴즈를 제출 후 정답 여부와 해설을 반환합니다.")
@Validated
@Operation(summary = "퀴즈 제출", description = "퀴즈를 제출 후 정답 여부와 해설을 반환합니다. 정답 선지 번호는 0부터 3까지입니다.")
@PostMapping("/{learningSetId}/quizzes/{quizId}")
public ResponseEntity<ApiResponse<Object>> submitAnswer(
final @AuthenticationPrincipal CustomUserDetails currentUser,
final @PathVariable("quizId") long quizId,
final @RequestBody @Valid SubmitAnswerRequest request) {
@RequestParam @Min(0) @Max(3) Integer answerIndex) {

QuizResultDTO quizResultDTO =
quizService.submitAnswer(currentUser.getId(), quizId, request.answerIndex());
quizService.submitAnswer(currentUser.getId(), quizId, answerIndex);

return ResponseEntity.status(HttpStatus.OK)
.body(ApiResponse.from(QuizResultResponse.toQuizResultResponse(quizResultDTO)));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import com.ripple.BE.user.domain.type.Level;
import com.ripple.BE.user.service.UserService;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -120,18 +122,19 @@ public QuizResultDTO submitAnswer(final long userId, final long quizId, final in
public void finishQuiz(final long userId, final long learningSetId, final Level level) {

User user = userService.findUserById(userId);
List<Integer> failList =
quizRedisService.fetchListFromRedis(userId, WRONG_ANSWER_TYPE, Integer.class);
Set<Integer> failSet =
new HashSet<>(
quizRedisService.fetchListFromRedis(userId, WRONG_ANSWER_TYPE, Integer.class));
UserLearningSet userLearningSet =
userLearningSetRepository
.findByUserIdAndLearningSetIdAndLevel(userId, learningSetId, level)
.orElseThrow(() -> new LearningException(LearningErrorCode.LEARNING_SET_NOT_FOUND));
List<FailQuiz> failQuizList =
failList.stream().map(quizId -> FailQuiz.toFailQuiz(user, getQuizById(quizId))).toList();
failSet.stream().map(quizId -> FailQuiz.toFailQuiz(user, getQuizById(quizId))).toList();
int quizCount = quizRedisService.fetchFromRedis(userId, QUIZ_COUNT, Integer.class);

if (!userLearningSet.isQuizCompleted()) {
int correctCount = quizCount - failList.size(); // 정답 개수 계산
int correctCount = quizCount - failSet.size(); // 정답 개수 계산
userLearningSet.setQuizCompleted(); // 퀴즈 완료 처리
userService.updateUserStatsAfterQuiz(
user, level, failQuizList, quizCount, correctCount); // 사용자 통계 업데이트
Expand Down

This file was deleted.

This file was deleted.