feat: quiz 수정 불가능한 상태로 변경 기능 추가
This commit is contained in:
parent
7826ad4ae7
commit
e78821332d
@ -28,6 +28,9 @@ public class QuizSet {
|
||||
@Column
|
||||
private String title;
|
||||
|
||||
@Column
|
||||
private boolean tested;
|
||||
|
||||
@OneToMany(mappedBy = "quizSet", orphanRemoval = true)
|
||||
@JsonManagedReference
|
||||
private List<Quiz> quizzes;
|
||||
|
@ -21,4 +21,6 @@ public interface QuizSetService {
|
||||
QuizSetResponse findQuizSetResponse(long quizSetId);
|
||||
|
||||
List<MyQuizSetResponse> findMyQuizSetResponses(long userId);
|
||||
|
||||
void updateQuizSetTested(long quizSetId, long userId, boolean tested);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user