From e78821332d3d9fd94ff50ddc4487cf91f2671aa3 Mon Sep 17 00:00:00 2001 From: kgc91747 Date: Thu, 8 Aug 2024 10:14:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20quiz=20=EC=88=98=EC=A0=95=20=EB=B6=88?= =?UTF-8?q?=EA=B0=80=EB=8A=A5=ED=95=9C=20=EC=83=81=ED=83=9C=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/edufocus/quiz/entity/QuizSet.java | 3 +++ .../edufocus/quiz/service/QuizSetService.java | 2 ++ .../edufocus/quiz/service/QuizSetServiceImpl.java | 15 +++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/backend/src/main/java/com/edufocus/edufocus/quiz/entity/QuizSet.java b/backend/src/main/java/com/edufocus/edufocus/quiz/entity/QuizSet.java index 90d13ac..19c7e35 100644 --- a/backend/src/main/java/com/edufocus/edufocus/quiz/entity/QuizSet.java +++ b/backend/src/main/java/com/edufocus/edufocus/quiz/entity/QuizSet.java @@ -28,6 +28,9 @@ public class QuizSet { @Column private String title; + @Column + private boolean tested; + @OneToMany(mappedBy = "quizSet", orphanRemoval = true) @JsonManagedReference private List quizzes; diff --git a/backend/src/main/java/com/edufocus/edufocus/quiz/service/QuizSetService.java b/backend/src/main/java/com/edufocus/edufocus/quiz/service/QuizSetService.java index a8c3fa0..97e75d2 100644 --- a/backend/src/main/java/com/edufocus/edufocus/quiz/service/QuizSetService.java +++ b/backend/src/main/java/com/edufocus/edufocus/quiz/service/QuizSetService.java @@ -21,4 +21,6 @@ public interface QuizSetService { QuizSetResponse findQuizSetResponse(long quizSetId); List findMyQuizSetResponses(long userId); + + void updateQuizSetTested(long quizSetId, long userId, boolean tested); } diff --git a/backend/src/main/java/com/edufocus/edufocus/quiz/service/QuizSetServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/quiz/service/QuizSetServiceImpl.java index b3b2b59..a636f0c 100644 --- a/backend/src/main/java/com/edufocus/edufocus/quiz/service/QuizSetServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/quiz/service/QuizSetServiceImpl.java @@ -3,6 +3,7 @@ package com.edufocus.edufocus.quiz.service; import com.edufocus.edufocus.quiz.entity.*; import com.edufocus.edufocus.quiz.repository.QuizSetRepository; import com.edufocus.edufocus.user.model.entity.vo.User; +import com.edufocus.edufocus.user.model.exception.UnAuthorizedException; import com.edufocus.edufocus.user.model.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; @@ -97,4 +98,18 @@ public class QuizSetServiceImpl implements QuizSetService { } + @Override + public void updateQuizSetTested(long quizSetId, long userId, boolean tested) { + QuizSet quizSet = quizSetRepository.findById(quizSetId).orElseThrow(NoSuchElementException::new); + + User user = userRepository.findById(userId).orElseThrow(NoSuchElementException::new); + + if (quizSet.getUser().getId() != user.getId()) { + throw new UnAuthorizedException(); + } + + quizSet.setTested(true); + quizSetRepository.save(quizSet); + } + }