Merge branch 'be/quiz' into 'backend'

feat: quiz 수정 불가능한 상태로 변경 기능 추가

See merge request s11-webmobile1-sub2/S11P12A701!101
This commit is contained in:
김한얼 2024-08-08 10:34:55 +09:00
commit c720d97985
3 changed files with 21 additions and 1 deletions

View File

@ -28,7 +28,10 @@ public class QuizSet {
@Column
private String title;
@OneToMany(mappedBy = "quizSet", orphanRemoval = true, fetch = FetchType.EAGER)
@Column
private boolean tested;
@OneToMany(mappedBy = "quizSet", orphanRemoval = true)
@JsonManagedReference
private List<Quiz> quizzes;

View File

@ -21,4 +21,6 @@ public interface QuizSetService {
QuizSetResponse findQuizSetResponse(long quizSetId);
List<MyQuizSetResponse> findMyQuizSetResponses(long userId);
void updateQuizSetTested(long quizSetId, long userId, boolean tested);
}

View File

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