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); + } + }