feat : reportDetail 수정
This commit is contained in:
parent
8c936e1762
commit
58ac496c41
@ -1,5 +1,6 @@
|
|||||||
package com.edufocus.edufocus.quiz.entity;
|
package com.edufocus.edufocus.quiz.entity;
|
||||||
|
|
||||||
|
import com.edufocus.edufocus.report.entity.dto.ChoiceDto;
|
||||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
@ -26,4 +27,11 @@ public class Choice {
|
|||||||
|
|
||||||
@Column
|
@Column
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
|
public ChoiceDto makeChoiceDto(){
|
||||||
|
return ChoiceDto.builder()
|
||||||
|
.num(num)
|
||||||
|
.content(content)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,8 @@ public class Registration {
|
|||||||
return Report.builder()
|
return Report.builder()
|
||||||
.allCount(0)
|
.allCount(0)
|
||||||
.correctCount(-1)
|
.correctCount(-1)
|
||||||
|
.reportSet(reportSet)
|
||||||
|
.quizSet(quizSet)
|
||||||
.lectureId(lectureId)
|
.lectureId(lectureId)
|
||||||
.user(user)
|
.user(user)
|
||||||
.build();
|
.build();
|
||||||
|
@ -55,6 +55,8 @@ public class ReportController {
|
|||||||
return new ResponseEntity<>(reportResponses, HttpStatus.OK);
|
return new ResponseEntity<>(reportResponses, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/reportDetail/{reportId}")
|
@GetMapping("/reportDetail/{reportId}")
|
||||||
public ResponseEntity<ReportDetailResponseDto> searchDetailReport(@PathVariable("reportId") long reportId){
|
public ResponseEntity<ReportDetailResponseDto> searchDetailReport(@PathVariable("reportId") long reportId){
|
||||||
ReportDetailResponseDto detailReport = reportService.reportDetail(reportId);
|
ReportDetailResponseDto detailReport = reportService.reportDetail(reportId);
|
||||||
@ -62,6 +64,9 @@ public class ReportController {
|
|||||||
return new ResponseEntity<>(detailReport, HttpStatus.OK);
|
return new ResponseEntity<>(detailReport, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/teacher/reportSet/{lectureId}")
|
@GetMapping("/teacher/reportSet/{lectureId}")
|
||||||
public ResponseEntity<List<ReportSetResponse>> searchReportSets(@PathVariable("lectureId") long lectureId){
|
public ResponseEntity<List<ReportSetResponse>> searchReportSets(@PathVariable("lectureId") long lectureId){
|
||||||
List<ReportSetResponse> reportSetResponses = reportService.findReportSets(lectureId);
|
List<ReportSetResponse> reportSetResponses = reportService.findReportSets(lectureId);
|
||||||
|
@ -18,5 +18,6 @@ public class QuizDto {
|
|||||||
private String image;
|
private String image;
|
||||||
private String answer;
|
private String answer;
|
||||||
private String userAnswer;
|
private String userAnswer;
|
||||||
|
private boolean isCollect;
|
||||||
private List<ChoiceDto> choices;
|
private List<ChoiceDto> choices;
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,5 @@ public class ReportDetailResponseDto {
|
|||||||
private String title;
|
private String title;
|
||||||
private int correctCount;
|
private int correctCount;
|
||||||
private LocalDateTime testAt;
|
private LocalDateTime testAt;
|
||||||
private List<QuizDto> correctQuizzes;
|
private List<QuizDto> quizzes;
|
||||||
private List<QuizDto> incorrectQuizzes;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -6,6 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface AnswerRepository extends JpaRepository<Answer, Long> {
|
public interface AnswerRepository extends JpaRepository<Answer, Long> {
|
||||||
List<Answer> findByReport_Id(Long reportId);
|
List<Answer> findByReportId(Long reportId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import com.edufocus.edufocus.quiz.entity.Quiz;
|
|||||||
import com.edufocus.edufocus.quiz.entity.QuizSet;
|
import com.edufocus.edufocus.quiz.entity.QuizSet;
|
||||||
import com.edufocus.edufocus.quiz.repository.QuizRepository;
|
import com.edufocus.edufocus.quiz.repository.QuizRepository;
|
||||||
import com.edufocus.edufocus.quiz.repository.QuizSetRepository;
|
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.Registration;
|
||||||
import com.edufocus.edufocus.registration.entity.RegistrationStatus;
|
import com.edufocus.edufocus.registration.entity.RegistrationStatus;
|
||||||
import com.edufocus.edufocus.registration.repository.RegistrationRepository;
|
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.AnswerRepository;
|
||||||
import com.edufocus.edufocus.report.repository.ReportRepository;
|
import com.edufocus.edufocus.report.repository.ReportRepository;
|
||||||
import com.edufocus.edufocus.report.repository.ReportSetRepository;
|
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 jakarta.transaction.Transactional;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -78,7 +74,6 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
|
|
||||||
report.setAllCount(quizList.size());
|
report.setAllCount(quizList.size());
|
||||||
report.setCorrectCount(correctCount);
|
report.setCorrectCount(correctCount);
|
||||||
report.setReportSet(reportSet);
|
|
||||||
|
|
||||||
reportRepository.save(report);
|
reportRepository.save(report);
|
||||||
|
|
||||||
@ -92,62 +87,40 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
|
|
||||||
QuizSet quizSet = quizSetRepository.findById(report.getQuizSet().getId()).orElseThrow(NoSuchElementException::new);
|
QuizSet quizSet = quizSetRepository.findById(report.getQuizSet().getId()).orElseThrow(NoSuchElementException::new);
|
||||||
|
|
||||||
List<QuizDto> correctQuiz = new ArrayList<>();
|
List<QuizDto> quizDtos = new ArrayList<>();
|
||||||
List<QuizDto> incorrectQuiz = new ArrayList<>();
|
|
||||||
|
|
||||||
List<Answer> myAnswer = answerRepository.findByReport_Id(report.getId());
|
List<Answer> myAnswer = answerRepository.findByReportId(report.getId());
|
||||||
|
|
||||||
for (Answer answer : myAnswer) {
|
for (Answer answer : myAnswer) {
|
||||||
QuizDto quizDto;
|
|
||||||
Quiz quiz = quizRepository.findById(answer.getQuiz().getId()).orElse(null);
|
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()) {
|
QuizDto quizDto = QuizDto.builder()
|
||||||
ChoiceDto choiceDto = null;
|
|
||||||
choiceDto = choiceDto.builder()
|
|
||||||
.num(c.getNum())
|
|
||||||
.content(c.getContent())
|
|
||||||
.build();
|
|
||||||
choiceDtos.add(choiceDto);
|
|
||||||
|
|
||||||
}
|
|
||||||
if (answer.isCorrect()) {
|
|
||||||
|
|
||||||
quizDto = QuizDto.builder()
|
|
||||||
.id(quiz.getId())
|
.id(quiz.getId())
|
||||||
.question(quiz.getQuestion())
|
.question(quiz.getQuestion())
|
||||||
.image(quiz.getImage())
|
.image(quiz.getImage())
|
||||||
.question(quiz.getQuestion())
|
.question(quiz.getQuestion())
|
||||||
.answer(quiz.getAnswer())
|
.answer(quiz.getAnswer())
|
||||||
.userAnswer(answer.getUserAnswer())
|
.userAnswer(answer.getUserAnswer())
|
||||||
|
.isCollect(answer.isCorrect())
|
||||||
.choices(choiceDtos)
|
.choices(choiceDtos)
|
||||||
.build();
|
.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())
|
.title(quizSet.getTitle())
|
||||||
.testAt(report.getTestAt())
|
.testAt(report.getTestAt())
|
||||||
.allCount(report.getAllCount())
|
.allCount(report.getAllCount())
|
||||||
.correctCount(report.getCorrectCount())
|
.correctCount(report.getCorrectCount())
|
||||||
.correctQuizzes(correctQuiz)
|
.quizzes(quizDtos)
|
||||||
.incorrectQuizzes(incorrectQuiz)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return dto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -179,8 +152,6 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID initReportSet(long lectureId, long quizSetId) {
|
public UUID initReportSet(long lectureId, long quizSetId) {
|
||||||
List<Registration> registrations = registrationRepository.findByLectureIdAndStatus(lectureId, RegistrationStatus.ACCEPTED);
|
|
||||||
|
|
||||||
ReportSet reportSet = ReportSet.builder()
|
ReportSet reportSet = ReportSet.builder()
|
||||||
.lecture(lectureRepository.getReferenceById(lectureId))
|
.lecture(lectureRepository.getReferenceById(lectureId))
|
||||||
.quizSet(quizSetRepository.getReferenceById(quizSetId))
|
.quizSet(quizSetRepository.getReferenceById(quizSetId))
|
||||||
@ -190,8 +161,9 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
|
|
||||||
QuizSet quizSet = quizSetRepository.getReferenceById(quizSetId);
|
QuizSet quizSet = quizSetRepository.getReferenceById(quizSetId);
|
||||||
|
|
||||||
|
List<Registration> registrations = registrationRepository.findByLectureIdAndStatus(lectureId, RegistrationStatus.ACCEPTED);
|
||||||
|
|
||||||
List<Report> reports = registrations.stream()
|
List<Report> reports = registrations.stream()
|
||||||
.filter(Registration::isAccepted)
|
|
||||||
.map((Registration registration)-> registration.makeReport(reportSet, quizSet, lectureId))
|
.map((Registration registration)-> registration.makeReport(reportSet, quizSet, lectureId))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ public interface UserService {
|
|||||||
|
|
||||||
boolean isEmailExist(String email);
|
boolean isEmailExist(String email);
|
||||||
|
|
||||||
|
boolean isTeacher(long userId);
|
||||||
|
|
||||||
void changeForgottenPassword(String email, String newPassword);
|
void changeForgottenPassword(String email, String newPassword);
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTeacher(long id){
|
public boolean isTeacher(long userId){
|
||||||
return userRepository.findById(id).orElseThrow(IllegalArgumentException::new).getRole() == UserRole.ADMIN;
|
return userRepository.findById(userId).orElseThrow(IllegalArgumentException::new).getRole() == UserRole.ADMIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user