feat : reportDetail 수정

This commit is contained in:
yulmam 2024-08-08 10:33:15 +09:00
parent 8c936e1762
commit 58ac496c41
9 changed files with 36 additions and 50 deletions

View File

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

View File

@ -41,6 +41,8 @@ public class Registration {
return Report.builder()
.allCount(0)
.correctCount(-1)
.reportSet(reportSet)
.quizSet(quizSet)
.lectureId(lectureId)
.user(user)
.build();

View File

@ -55,6 +55,8 @@ public class ReportController {
return new ResponseEntity<>(reportResponses, HttpStatus.OK);
}
@GetMapping("/reportDetail/{reportId}")
public ResponseEntity<ReportDetailResponseDto> 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<List<ReportSetResponse>> searchReportSets(@PathVariable("lectureId") long lectureId){
List<ReportSetResponse> reportSetResponses = reportService.findReportSets(lectureId);

View File

@ -18,5 +18,6 @@ public class QuizDto {
private String image;
private String answer;
private String userAnswer;
private boolean isCollect;
private List<ChoiceDto> choices;
}

View File

@ -15,8 +15,5 @@ public class ReportDetailResponseDto {
private String title;
private int correctCount;
private LocalDateTime testAt;
private List<QuizDto> correctQuizzes;
private List<QuizDto> incorrectQuizzes;
private List<QuizDto> quizzes;
}

View File

@ -6,6 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface AnswerRepository extends JpaRepository<Answer, Long> {
List<Answer> findByReport_Id(Long reportId);
List<Answer> findByReportId(Long reportId);
}

View File

@ -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<QuizDto> correctQuiz = new ArrayList<>();
List<QuizDto> incorrectQuiz = new ArrayList<>();
List<QuizDto> quizDtos = new ArrayList<>();
List<Answer> myAnswer = answerRepository.findByReport_Id(report.getId());
List<Answer> myAnswer = answerRepository.findByReportId(report.getId());
for (Answer answer : myAnswer) {
QuizDto quizDto;
Quiz quiz = quizRepository.findById(answer.getQuiz().getId()).orElse(null);
ArrayList<ChoiceDto> choiceDtos = new ArrayList<>();
List<ChoiceDto> 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<Registration> 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<Registration> registrations = registrationRepository.findByLectureIdAndStatus(lectureId, RegistrationStatus.ACCEPTED);
List<Report> reports = registrations.stream()
.filter(Registration::isAccepted)
.map((Registration registration)-> registration.makeReport(reportSet, quizSet, lectureId))
.toList();

View File

@ -28,6 +28,7 @@ public interface UserService {
boolean isEmailExist(String email);
boolean isTeacher(long userId);
void changeForgottenPassword(String email, String newPassword);
}

View File

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