Merge branch 'BE/userinfo' into 'backend'
feat: qna 답변 수정 See merge request s11-webmobile1-sub2/S11P12A701!88
This commit is contained in:
commit
47d480210e
@ -7,6 +7,7 @@ import com.edufocus.edufocus.qna.entity.QnaRequestDto;
|
||||
import com.edufocus.edufocus.qna.entity.QnaResponseDto;
|
||||
import com.edufocus.edufocus.qna.repository.QnaRepository;
|
||||
import com.edufocus.edufocus.user.model.entity.vo.User;
|
||||
import com.edufocus.edufocus.user.model.entity.vo.UserRole;
|
||||
import com.edufocus.edufocus.user.model.repository.UserRepository;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -24,14 +25,13 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
@Transactional
|
||||
@RequiredArgsConstructor
|
||||
public class QnaServiceImpl implements QnaService{
|
||||
public class QnaServiceImpl implements QnaService {
|
||||
|
||||
private final QnaRepository qnaRepository;
|
||||
private final LectureRepository lectureRepository;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public QnaResponseDto createQna(Long id, QnaRequestDto qnaRequestDto, Long lecture_id) {
|
||||
|
||||
@ -41,19 +41,21 @@ public class QnaServiceImpl implements QnaService{
|
||||
User user = userRepository.findById(id).orElse(null);
|
||||
|
||||
|
||||
|
||||
Qna qna = QnaRequestDto.toEntity(qnaRequestDto);
|
||||
if (qna.getAnswer() != null || user.getRole() != UserRole.ADMIN) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
qna.setLecture(lecture);
|
||||
qna.setUser(user);
|
||||
|
||||
qna.setCreatedAt(new Date());
|
||||
|
||||
qnaRepository.save(qna);
|
||||
return QnaResponseDto.toEntity(qna);
|
||||
return QnaResponseDto.toEntity(qna);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QnaResponseDto updateQna(Long id,QnaRequestDto qnaRequestDto) {
|
||||
public QnaResponseDto updateQna(Long id, QnaRequestDto qnaRequestDto) {
|
||||
|
||||
|
||||
Qna findQna = qnaRepository.findById(id)
|
||||
@ -65,14 +67,14 @@ public class QnaServiceImpl implements QnaService{
|
||||
|
||||
qnaRepository.save(findQna);
|
||||
|
||||
return QnaResponseDto.toEntity(findQna);
|
||||
return QnaResponseDto.toEntity(findQna);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteQna(Long id) {
|
||||
qnaRepository.deleteById(id);
|
||||
qnaRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,7 +82,7 @@ qnaRepository.deleteById(id);
|
||||
Optional<Qna> qna;
|
||||
try {
|
||||
|
||||
qna= qnaRepository.findById(id);
|
||||
qna = qnaRepository.findById(id);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
@ -89,14 +91,12 @@ qnaRepository.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return QnaResponseDto.toEntity(qna.get());
|
||||
return QnaResponseDto.toEntity(qna.get());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QnaResponseDto> getAllQnasByLecture(Long lectureId,int pageSize)
|
||||
{
|
||||
public List<QnaResponseDto> getAllQnasByLecture(Long lectureId, int pageSize) {
|
||||
|
||||
Pageable pageable = PageRequest.of(0, pageSize);
|
||||
|
||||
|
@ -60,7 +60,6 @@ public class ReportServiceImpl implements ReportService {
|
||||
Quiz quiz = quizList.get(idx);
|
||||
String inputAnswer = answerInputList.get(idx);
|
||||
Answer answer;
|
||||
//
|
||||
if (quiz.getAnswer().equals(inputAnswer)) {
|
||||
correctCount++;
|
||||
answer = Answer.builder()
|
||||
@ -183,6 +182,7 @@ public class ReportServiceImpl implements ReportService {
|
||||
|
||||
List<Report> reportList = reportRepository.findByUser_Id(userId);
|
||||
|
||||
|
||||
List<ReportListResponseDto> reportListResponseDtoList = new ArrayList<>();
|
||||
|
||||
|
||||
|
@ -93,6 +93,8 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
if (!PasswordUtils.checkPassword(passwordDto.getCurrentPassword(), user.getPassword())) {
|
||||
throw new UserException("Current password is incorrect");
|
||||
} else if (passwordDto.getCurrentPassword().equals(passwordDto.getNewPassword())) {
|
||||
throw new UserException("New password cannot be the same as the current password");
|
||||
} else {
|
||||
if (!passwordDto.getNewPassword().equals(passwordDto.getNewPasswordCheck())) {
|
||||
throw new UserException("New password confirmation does not match");
|
||||
|
Loading…
Reference in New Issue
Block a user