Skip to content

Commit

Permalink
refactor: 교육 시작 시 캐시에 정답 저장 메서드 위치 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Youthhing committed Aug 14, 2024
1 parent 8cfc503 commit 0aab669
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class SocketController {
@PatchMapping("/start/csquiz")
public ResponseEntity<Void> openCSQuiz(@RequestBody @Valid QuizOpenRequest request) {
educationService.openCSQuiz(request);
recordService.saveAnswersToCache(request);
return ResponseEntity.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@Slf4j
public class EducationService {

private final RecordService recordService;
private final EducationRepository educationRepository;
private final QuizRepository quizRepository;
private final SessionRepository sessionRepository;
Expand Down Expand Up @@ -93,6 +94,7 @@ public void openCSQuiz(QuizOpenRequest request) {
checkEducationBefore(education);

education.updateStatus(EducationStatus.ONGOING);
recordService.saveAnswersToCache(education.getId());
}

private void checkEducationBefore(Education education) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.cotato.csquiz.api.record.dto.ReplyRequest;
import org.cotato.csquiz.api.record.dto.ReplyResponse;
import org.cotato.csquiz.api.record.dto.ScorerResponse;
import org.cotato.csquiz.api.socket.dto.QuizOpenRequest;
import org.cotato.csquiz.api.socket.dto.QuizSocketRequest;
import org.cotato.csquiz.common.error.ErrorCode;
import org.cotato.csquiz.common.error.exception.AppException;
Expand Down Expand Up @@ -96,8 +95,8 @@ private Quiz findQuizById(Long quizId) {
.orElseThrow(() -> new EntityNotFoundException("해당 문제를 찾을 수 없습니다."));
}

public void saveAnswersToCache(QuizOpenRequest request) {
List<Quiz> quizzes = quizRepository.findAllByEducationId(request.educationId());
public void saveAnswersToCache(final Long educationId) {
List<Quiz> quizzes = quizRepository.findAllByEducationId(educationId);

quizAnswerRedisRepository.saveAllQuizAnswers(quizzes);
}
Expand Down

0 comments on commit 0aab669

Please sign in to comment.