diff --git a/backend/src/main/java/com/edufocus/edufocus/quiz/entity/Choice.java b/backend/src/main/java/com/edufocus/edufocus/quiz/entity/Choice.java index 8078db1..b8e82c2 100644 --- a/backend/src/main/java/com/edufocus/edufocus/quiz/entity/Choice.java +++ b/backend/src/main/java/com/edufocus/edufocus/quiz/entity/Choice.java @@ -1,5 +1,6 @@ package com.edufocus.edufocus.quiz.entity; +import com.edufocus.edufocus.report.entity.dto.ChoiceDto; import com.fasterxml.jackson.annotation.JsonBackReference; import jakarta.persistence.*; import lombok.*; @@ -26,4 +27,11 @@ public class Choice { @Column private String content; + + public ChoiceDto makeChoiceDto(){ + return ChoiceDto.builder() + .num(num) + .content(content) + .build(); + } } diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java b/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java index 0b01d55..c5d302a 100644 --- a/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java +++ b/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java @@ -41,6 +41,8 @@ public class Registration { return Report.builder() .allCount(0) .correctCount(-1) + .reportSet(reportSet) + .quizSet(quizSet) .lectureId(lectureId) .user(user) .build(); diff --git a/backend/src/main/java/com/edufocus/edufocus/report/controller/ReportController.java b/backend/src/main/java/com/edufocus/edufocus/report/controller/ReportController.java index bc9b5f2..673bf19 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/controller/ReportController.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/controller/ReportController.java @@ -55,6 +55,8 @@ public class ReportController { return new ResponseEntity<>(reportResponses, HttpStatus.OK); } + + @GetMapping("/reportDetail/{reportId}") public ResponseEntity searchDetailReport(@PathVariable("reportId") long reportId){ ReportDetailResponseDto detailReport = reportService.reportDetail(reportId); @@ -62,6 +64,9 @@ public class ReportController { return new ResponseEntity<>(detailReport, HttpStatus.OK); } + + + @GetMapping("/teacher/reportSet/{lectureId}") public ResponseEntity> searchReportSets(@PathVariable("lectureId") long lectureId){ List reportSetResponses = reportService.findReportSets(lectureId); diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/QuizDto.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/QuizDto.java index d73d6fb..d36281f 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/QuizDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/QuizDto.java @@ -18,5 +18,6 @@ public class QuizDto { private String image; private String answer; private String userAnswer; + private boolean isCollect; private List choices; } diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportDetailResponseDto.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportDetailResponseDto.java index 4dc0f76..6ef9d9c 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportDetailResponseDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportDetailResponseDto.java @@ -15,8 +15,5 @@ public class ReportDetailResponseDto { private String title; private int correctCount; private LocalDateTime testAt; - private List correctQuizzes; - private List incorrectQuizzes; - - + private List quizzes; } \ No newline at end of file diff --git a/backend/src/main/java/com/edufocus/edufocus/report/repository/AnswerRepository.java b/backend/src/main/java/com/edufocus/edufocus/report/repository/AnswerRepository.java index 2a9787f..0998a0a 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/repository/AnswerRepository.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/repository/AnswerRepository.java @@ -6,6 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; public interface AnswerRepository extends JpaRepository { - List findByReport_Id(Long reportId); + List findByReportId(Long reportId); } diff --git a/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java index 016bb34..3ae6792 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java @@ -6,7 +6,6 @@ import com.edufocus.edufocus.quiz.entity.Quiz; import com.edufocus.edufocus.quiz.entity.QuizSet; import com.edufocus.edufocus.quiz.repository.QuizRepository; import com.edufocus.edufocus.quiz.repository.QuizSetRepository; -import com.edufocus.edufocus.quiz.service.QuizSetService; import com.edufocus.edufocus.registration.entity.Registration; import com.edufocus.edufocus.registration.entity.RegistrationStatus; import com.edufocus.edufocus.registration.repository.RegistrationRepository; @@ -17,13 +16,10 @@ import com.edufocus.edufocus.report.entity.vo.ReportSet; import com.edufocus.edufocus.report.repository.AnswerRepository; import com.edufocus.edufocus.report.repository.ReportRepository; import com.edufocus.edufocus.report.repository.ReportSetRepository; -import com.edufocus.edufocus.user.model.entity.vo.User; -import com.edufocus.edufocus.user.model.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import java.sql.SQLException; import java.util.*; @Service @@ -78,7 +74,6 @@ public class ReportServiceImpl implements ReportService { report.setAllCount(quizList.size()); report.setCorrectCount(correctCount); - report.setReportSet(reportSet); reportRepository.save(report); @@ -92,62 +87,40 @@ public class ReportServiceImpl implements ReportService { QuizSet quizSet = quizSetRepository.findById(report.getQuizSet().getId()).orElseThrow(NoSuchElementException::new); - List correctQuiz = new ArrayList<>(); - List incorrectQuiz = new ArrayList<>(); + List quizDtos = new ArrayList<>(); - List myAnswer = answerRepository.findByReport_Id(report.getId()); + List myAnswer = answerRepository.findByReportId(report.getId()); for (Answer answer : myAnswer) { - QuizDto quizDto; Quiz quiz = quizRepository.findById(answer.getQuiz().getId()).orElse(null); - ArrayList choiceDtos = new ArrayList<>(); + List choiceDtos = quiz.getChoices() + .stream() + .map(Choice::makeChoiceDto) + .toList(); - for (Choice c : quiz.getChoices()) { - ChoiceDto choiceDto = null; - choiceDto = choiceDto.builder() - .num(c.getNum()) - .content(c.getContent()) - .build(); - choiceDtos.add(choiceDto); - - } - if (answer.isCorrect()) { - - quizDto = QuizDto.builder() + QuizDto quizDto = QuizDto.builder() .id(quiz.getId()) .question(quiz.getQuestion()) .image(quiz.getImage()) .question(quiz.getQuestion()) .answer(quiz.getAnswer()) .userAnswer(answer.getUserAnswer()) + .isCollect(answer.isCorrect()) .choices(choiceDtos) .build(); - correctQuiz.add(quizDto); - } else { - quizDto = QuizDto.builder() - .id(quiz.getId()) - .question(quiz.getQuestion()) - .image(quiz.getImage()) - .question(quiz.getQuestion()) - .answer(quiz.getAnswer()) - .userAnswer(answer.getUserAnswer()) - .choices(choiceDtos) - .build(); - incorrectQuiz.add(quizDto); - } + quizDtos.add(quizDto); } - ReportDetailResponseDto dto = ReportDetailResponseDto.builder() + + + return ReportDetailResponseDto.builder() .title(quizSet.getTitle()) .testAt(report.getTestAt()) .allCount(report.getAllCount()) .correctCount(report.getCorrectCount()) - .correctQuizzes(correctQuiz) - .incorrectQuizzes(incorrectQuiz) + .quizzes(quizDtos) .build(); - - return dto; } @Override @@ -179,8 +152,6 @@ public class ReportServiceImpl implements ReportService { @Override public UUID initReportSet(long lectureId, long quizSetId) { - List registrations = registrationRepository.findByLectureIdAndStatus(lectureId, RegistrationStatus.ACCEPTED); - ReportSet reportSet = ReportSet.builder() .lecture(lectureRepository.getReferenceById(lectureId)) .quizSet(quizSetRepository.getReferenceById(quizSetId)) @@ -190,8 +161,9 @@ public class ReportServiceImpl implements ReportService { QuizSet quizSet = quizSetRepository.getReferenceById(quizSetId); + List registrations = registrationRepository.findByLectureIdAndStatus(lectureId, RegistrationStatus.ACCEPTED); + List reports = registrations.stream() - .filter(Registration::isAccepted) .map((Registration registration)-> registration.makeReport(reportSet, quizSet, lectureId)) .toList(); diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java index eccbc12..7a42d0d 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java @@ -28,6 +28,7 @@ public interface UserService { boolean isEmailExist(String email); + boolean isTeacher(long userId); void changeForgottenPassword(String email, String newPassword); } diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java index 68f4e3b..ac6a6d8 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java @@ -159,7 +159,7 @@ public class UserServiceImpl implements UserService { } @Override - public boolean isTeacher(long id){ - return userRepository.findById(id).orElseThrow(IllegalArgumentException::new).getRole() == UserRole.ADMIN; + public boolean isTeacher(long userId){ + return userRepository.findById(userId).orElseThrow(IllegalArgumentException::new).getRole() == UserRole.ADMIN; } }