Merge branch 'BE/userinfo' into 'backend'
feat: report 조회 기능 추가 See merge request s11-webmobile1-sub2/S11P12A701!69
This commit is contained in:
commit
fdcec9baac
@ -1,19 +1,23 @@
|
|||||||
package com.edufocus.edufocus.report.controller;
|
package com.edufocus.edufocus.report.controller;
|
||||||
|
|
||||||
|
import com.edufocus.edufocus.report.entity.dto.ReportDetailResponseDto;
|
||||||
|
import com.edufocus.edufocus.report.entity.dto.ReportListResponseDto;
|
||||||
import com.edufocus.edufocus.report.entity.dto.ReportResponse;
|
import com.edufocus.edufocus.report.entity.dto.ReportResponse;
|
||||||
import com.edufocus.edufocus.report.entity.vo.Report;
|
import com.edufocus.edufocus.report.entity.vo.Report;
|
||||||
import com.edufocus.edufocus.report.entity.dto.ReportRequset;
|
import com.edufocus.edufocus.report.entity.dto.ReportRequset;
|
||||||
import com.edufocus.edufocus.report.service.ReportService;
|
import com.edufocus.edufocus.report.service.ReportService;
|
||||||
|
import com.edufocus.edufocus.user.util.JWTUtil;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/report")
|
@RequestMapping("/report")
|
||||||
@ -23,15 +27,36 @@ public class ReportController{
|
|||||||
|
|
||||||
|
|
||||||
private final ReportService reportService;
|
private final ReportService reportService;
|
||||||
|
private final JWTUtil jwtUtil;
|
||||||
|
|
||||||
|
@PostMapping("/submit/{quizsetId}")
|
||||||
|
public ResponseEntity<ReportResponse> submit(@PathVariable("quizsetId") Long quizestId, @RequestBody ReportRequset reportRequset, HttpServletRequest request) throws SQLException {
|
||||||
|
|
||||||
|
String token = request.getHeader("Authorization");
|
||||||
|
Long userId = Long.parseLong(jwtUtil.getUserId(token));
|
||||||
|
|
||||||
|
ReportResponse report = reportService.grading(userId, quizestId, reportRequset);
|
||||||
@PostMapping("/submit")
|
|
||||||
public ResponseEntity<ReportResponse> submit(@RequestBody ReportRequset reportRequset) throws SQLException {
|
|
||||||
ReportResponse report = reportService.grading(reportRequset);
|
|
||||||
return new ResponseEntity<>(report, HttpStatus.CREATED);
|
return new ResponseEntity<>(report, HttpStatus.CREATED);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/myreport/{id}")
|
||||||
|
public ResponseEntity<List<ReportListResponseDto>> reportList(@PathVariable Long id, HttpServletRequest request) throws SQLException {
|
||||||
|
String token = request.getHeader("Authorization");
|
||||||
|
Long userId = Long.parseLong(jwtUtil.getUserId(token));
|
||||||
|
List<ReportListResponseDto> reportList = reportService.resultList(userId);
|
||||||
|
|
||||||
|
return new ResponseEntity<>(reportList, HttpStatus.CREATED);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/detailreport/{id}")
|
||||||
|
public ResponseEntity<ReportDetailResponseDto> myReport(@PathVariable("id") Long reportId) throws SQLException {
|
||||||
|
|
||||||
|
ReportDetailResponseDto detailReport = reportService.reportDetail(reportId);
|
||||||
|
return new ResponseEntity<>(detailReport, HttpStatus.CREATED);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
public class AnswerInput {
|
public class AnswerInput {
|
||||||
|
|
||||||
Long answerinputID;
|
|
||||||
String answer;
|
String answer;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.edufocus.edufocus.report.entity.dto;
|
||||||
|
|
||||||
|
import com.edufocus.edufocus.quiz.entity.Quiz;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class ReportDetailResponseDto {
|
||||||
|
private int allCount;
|
||||||
|
private String title;
|
||||||
|
private int correctCount;
|
||||||
|
private Date testAt;
|
||||||
|
private List<Quiz> correctQuizzes;
|
||||||
|
private List<Quiz> incorrectQuizzes;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.edufocus.edufocus.report.entity.dto;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class ReportListResponseDto {
|
||||||
|
private String title;
|
||||||
|
private Date date;
|
||||||
|
private Long reportId;
|
||||||
|
}
|
@ -10,11 +10,9 @@ import java.util.List;
|
|||||||
public class ReportRequset {
|
public class ReportRequset {
|
||||||
|
|
||||||
|
|
||||||
private Long userId;
|
|
||||||
private Long quizsetId;
|
|
||||||
List<AnswerInput> answerInputList;
|
List<AnswerInput> answerInputList;
|
||||||
|
|
||||||
|
// [1,2,,3]
|
||||||
// List<answerDto> a
|
// List<answerDto> a
|
||||||
// userID :
|
// userID :
|
||||||
// quizSetId :
|
// quizSetId :
|
||||||
|
@ -3,5 +3,9 @@ package com.edufocus.edufocus.report.repository;
|
|||||||
import com.edufocus.edufocus.report.entity.vo.Answer;
|
import com.edufocus.edufocus.report.entity.vo.Answer;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface AnswerRepository extends JpaRepository<Answer, Long> {
|
public interface AnswerRepository extends JpaRepository<Answer, Long> {
|
||||||
|
List<Answer> findByReport_Id(Long reportId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,10 @@ import com.edufocus.edufocus.report.entity.vo.Report;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface ReportRepository extends JpaRepository<Report, Long> {
|
public interface ReportRepository extends JpaRepository<Report, Long> {
|
||||||
|
List<Report> findByUser_Id(Long userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
package com.edufocus.edufocus.report.service;
|
package com.edufocus.edufocus.report.service;
|
||||||
|
|
||||||
|
import com.edufocus.edufocus.report.entity.dto.ReportDetailResponseDto;
|
||||||
|
import com.edufocus.edufocus.report.entity.dto.ReportListResponseDto;
|
||||||
import com.edufocus.edufocus.report.entity.dto.ReportResponse;
|
import com.edufocus.edufocus.report.entity.dto.ReportResponse;
|
||||||
import com.edufocus.edufocus.report.entity.vo.Report;
|
|
||||||
import com.edufocus.edufocus.report.entity.dto.ReportRequset;
|
import com.edufocus.edufocus.report.entity.dto.ReportRequset;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public interface ReportService {
|
public interface ReportService {
|
||||||
ReportResponse grading(ReportRequset reportRequset) throws SQLException;
|
ReportResponse grading(Long userId, Long quizesetId, ReportRequset reportRequset) throws SQLException;
|
||||||
|
|
||||||
|
ReportDetailResponseDto reportDetail(Long userId) throws SQLException;
|
||||||
|
|
||||||
|
List<ReportListResponseDto> resultList(Long userId) throws SQLException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,12 @@ package com.edufocus.edufocus.report.service;
|
|||||||
import com.edufocus.edufocus.quiz.entity.Quiz;
|
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.service.QuizService;
|
import com.edufocus.edufocus.quiz.service.QuizService;
|
||||||
import com.edufocus.edufocus.quiz.service.QuizSetService;
|
import com.edufocus.edufocus.quiz.service.QuizSetService;
|
||||||
import com.edufocus.edufocus.report.entity.dto.ReportResponse;
|
import com.edufocus.edufocus.report.entity.dto.*;
|
||||||
import com.edufocus.edufocus.report.entity.vo.Answer;
|
import com.edufocus.edufocus.report.entity.vo.Answer;
|
||||||
import com.edufocus.edufocus.report.entity.dto.AnswerInput;
|
|
||||||
import com.edufocus.edufocus.report.entity.vo.Report;
|
import com.edufocus.edufocus.report.entity.vo.Report;
|
||||||
import com.edufocus.edufocus.report.entity.dto.ReportRequset;
|
|
||||||
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.user.model.entity.vo.User;
|
import com.edufocus.edufocus.user.model.entity.vo.User;
|
||||||
@ -34,15 +33,17 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
private final ReportRepository reportRepository;
|
private final ReportRepository reportRepository;
|
||||||
private final QuizRepository quizRepository;
|
private final QuizRepository quizRepository;
|
||||||
|
|
||||||
|
|
||||||
private final AnswerRepository answerRepository;
|
private final AnswerRepository answerRepository;
|
||||||
private final AnswerService answerService;
|
private final AnswerService answerService;
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
private final QuizSetRepository quizSetRepository;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReportResponse grading(ReportRequset reportRequset) throws SQLException {
|
public ReportResponse grading(Long userId, Long quizsetId, ReportRequset reportRequset) throws SQLException {
|
||||||
|
|
||||||
QuizSet quizSet = quizSetService.findQuizSet(reportRequset.getQuizsetId());
|
QuizSet quizSet = quizSetService.findQuizSet(quizsetId);
|
||||||
List<Quiz> quizList = quizSet.getQuizzes();
|
List<Quiz> quizList = quizSet.getQuizzes();
|
||||||
List<AnswerInput> answerInputList = reportRequset.getAnswerInputList();
|
List<AnswerInput> answerInputList = reportRequset.getAnswerInputList();
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
int allCount = quizList.size();
|
int allCount = quizList.size();
|
||||||
int correctCount = 0;
|
int correctCount = 0;
|
||||||
|
|
||||||
User testuser = userRepository.findById(reportRequset.getUserId()).orElse(null);
|
User testuser = userRepository.findById(userId).orElse(null);
|
||||||
|
|
||||||
for (int idx = 0; idx < answerInputList.size(); idx++) {
|
for (int idx = 0; idx < answerInputList.size(); idx++) {
|
||||||
Quiz quiz = quizList.get(idx);
|
Quiz quiz = quizList.get(idx);
|
||||||
@ -107,4 +108,105 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
return reportResponse;
|
return reportResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReportDetailResponseDto reportDetail(Long repordId) {
|
||||||
|
|
||||||
|
Report report = reportRepository.findById(repordId).orElse(null);
|
||||||
|
|
||||||
|
QuizSet quizSet = quizSetService.findQuizSet(report.getQuizSet().getId());
|
||||||
|
|
||||||
|
List<Quiz> correctQuiz = new ArrayList<>();
|
||||||
|
List<Quiz> incorrectQuiz = new ArrayList<>();
|
||||||
|
|
||||||
|
List<Answer> myAnswer = answerRepository.findByReport_Id(report.getId());
|
||||||
|
|
||||||
|
for (Answer answer : myAnswer) {
|
||||||
|
if (answer.isCorrect()) {
|
||||||
|
correctQuiz.add(quizRepository.findById(answer.getQuiz().getId()).orElse(null));
|
||||||
|
} else {
|
||||||
|
incorrectQuiz.add(quizRepository.findById(answer.getQuiz().getId()).orElse(null));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ReportDetailResponseDto dto = ReportDetailResponseDto.builder()
|
||||||
|
.title(quizSet.getTitle())
|
||||||
|
.testAt(report.getTestAt())
|
||||||
|
.allCount(report.getAllCount())
|
||||||
|
.correctCount(report.getCorrectCount())
|
||||||
|
.correctQuizzes(correctQuiz)
|
||||||
|
.incorrectQuizzes(incorrectQuiz)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public List<ReportResultResponseDto> result(Long userId) throws SQLException {
|
||||||
|
// List<Report> myReport = reportRepository.findByUser_Id(userId);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// List<ReportResultResponseDto> responseDtos = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// for (Report report : myReport) {
|
||||||
|
// int all = report.getAllCount();
|
||||||
|
// int correctCount = report.getCorrectCount();
|
||||||
|
// Long quizsetId = report.getQuizSet().getId();
|
||||||
|
// Date testAt = report.getTestAt();
|
||||||
|
//
|
||||||
|
// List<Quiz> correctQuiz = new ArrayList<>();
|
||||||
|
// List<Quiz> incorrectQuiz = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// List<Answer> myAnswer = answerRepository.findByReport_Id(report.getId());
|
||||||
|
//
|
||||||
|
// for (Answer answer : myAnswer) {
|
||||||
|
// if (answer.isCorrect()) {
|
||||||
|
// correctQuiz.add(quizRepository.findById(answer.getQuiz().getId()).orElse(null));
|
||||||
|
// } else {
|
||||||
|
// incorrectQuiz.add(quizRepository.findById(answer.getQuiz().getId()).orElse(null));
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// ReportResultResponseDto dto = ReportResultResponseDto.builder()
|
||||||
|
// .reportId(report.getId())
|
||||||
|
// .allCount(all)
|
||||||
|
// .correctCount(correctCount)
|
||||||
|
// .quizSetId(quizSetId)
|
||||||
|
// .testAt(testAt)
|
||||||
|
// .correctQuizzes(correctQuiz)
|
||||||
|
// .incorrectQuizzes(incorrectQuiz)
|
||||||
|
// .build();
|
||||||
|
//
|
||||||
|
// responseDtos.add(dto);
|
||||||
|
// }
|
||||||
|
// // 틀린문제
|
||||||
|
// // 내가 체크한 번호
|
||||||
|
// // 정답 번호
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ReportListResponseDto> resultList(Long userId) throws SQLException {
|
||||||
|
|
||||||
|
List<Report> reportList = reportRepository.findByUser_Id(userId);
|
||||||
|
|
||||||
|
List<ReportListResponseDto> reportListResponseDtoList = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
for (Report report : reportList) {
|
||||||
|
|
||||||
|
QuizSet quizSet = quizSetService.findQuizSet(report.getQuizSet().getId());
|
||||||
|
ReportListResponseDto dto = ReportListResponseDto.builder()
|
||||||
|
.title(quizSet.getTitle()) // Assuming QuizSet has a method getTitle()
|
||||||
|
.date(report.getTestAt())
|
||||||
|
.reportId(report.getId())// Assuming QuizSet has a method getDate()
|
||||||
|
.build();
|
||||||
|
reportListResponseDtoList.add(dto);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return reportListResponseDtoList;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user