Merge branch 'BE/userinfo' into 'backend'
feat: 퀴즈 채점 기능 수정 See merge request s11-webmobile1-sub2/S11P12A701!63
This commit is contained in:
commit
7d396c2eab
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
@ -17,16 +17,15 @@ public class Answer {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
private String userAnswer;
|
||||
private boolean isCorrect;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name= "report_id")
|
||||
@JoinColumn(name = "report_id")
|
||||
private Report report;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name= "quiz_id")
|
||||
@JoinColumn(name = "quiz_id")
|
||||
private Quiz quiz;
|
||||
|
||||
|
||||
|
@ -10,6 +10,7 @@ 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.dto.ReportRequset;
|
||||
import com.edufocus.edufocus.report.repository.AnswerRepository;
|
||||
import com.edufocus.edufocus.report.repository.ReportRepository;
|
||||
import com.edufocus.edufocus.user.model.entity.vo.User;
|
||||
import com.edufocus.edufocus.user.model.repository.UserRepository;
|
||||
@ -18,6 +19,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -32,6 +34,7 @@ public class ReportServiceImpl implements ReportService {
|
||||
private final ReportRepository reportRepository;
|
||||
private final QuizRepository quizRepository;
|
||||
|
||||
private final AnswerRepository answerRepository;
|
||||
private final AnswerService answerService;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@ -39,56 +42,59 @@ public class ReportServiceImpl implements ReportService {
|
||||
@Override
|
||||
public ReportResponse grading(ReportRequset reportRequset) throws SQLException {
|
||||
|
||||
|
||||
QuizSet quizSet = quizSetService.findQuizSet(reportRequset.getQuizsetId());
|
||||
System.out.println(quizSet.toString());
|
||||
List<Quiz> quizList = quizSet.getQuizzes();
|
||||
List<AnswerInput> answerInputList = reportRequset.getAnswerInputList();
|
||||
|
||||
Report report = new Report();
|
||||
List<Answer> answerList = new ArrayList<>();
|
||||
|
||||
Long reportNum = report.getId();
|
||||
int allCount = quizList.size();
|
||||
int correctCount = 0;
|
||||
|
||||
User testuser = userRepository.findById(reportRequset.getUserId()).orElse(null);
|
||||
|
||||
for (Quiz quiz : quizList) {
|
||||
for (AnswerInput answerInput : answerInputList) {
|
||||
if (quiz.getId() == answerInput.getAnswerinputID()) {
|
||||
|
||||
if (quiz.getAnswer().equals(answerInput.getAnswer())) {
|
||||
correctCount++;
|
||||
|
||||
Answer answer = Answer.builder()
|
||||
.userAnswer(answerInput.getAnswer())
|
||||
.isCorrect(true)
|
||||
.report(report)
|
||||
.quiz(quiz)
|
||||
.build();
|
||||
|
||||
} else {
|
||||
Answer answer = Answer.builder()
|
||||
.userAnswer(answerInput.getAnswer())
|
||||
.isCorrect(false)
|
||||
.report(report)
|
||||
.quiz(quiz)
|
||||
.build();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (int idx = 0; idx < answerInputList.size(); idx++) {
|
||||
Quiz quiz = quizList.get(idx);
|
||||
AnswerInput inputAnswer = answerInputList.get(idx);
|
||||
Answer answer;
|
||||
if (quiz.getAnswer().equals(inputAnswer.getAnswer())) {
|
||||
correctCount++;
|
||||
answer = Answer.builder()
|
||||
.userAnswer(inputAnswer.getAnswer())
|
||||
.isCorrect(true)
|
||||
.report(null)
|
||||
.quiz(quiz)
|
||||
.build();
|
||||
} else {
|
||||
answer = Answer.builder()
|
||||
.userAnswer(inputAnswer.getAnswer())
|
||||
.isCorrect(false)
|
||||
.report(null)
|
||||
.quiz(quiz)
|
||||
.build();
|
||||
}
|
||||
answerList.add(answer);
|
||||
}
|
||||
|
||||
report = Report.builder()
|
||||
|
||||
Report report = Report.builder()
|
||||
.user(testuser)
|
||||
.quizSet(quizSet)
|
||||
.allCount(allCount)
|
||||
.correctCount(correctCount)
|
||||
.testAt(new Date()).build();
|
||||
.testAt(new Date())
|
||||
.build();
|
||||
|
||||
|
||||
reportRepository.save(report);
|
||||
|
||||
|
||||
for (Answer answer : answerList) {
|
||||
answer.setReport(report);
|
||||
answerRepository.save(answer);
|
||||
}
|
||||
|
||||
|
||||
ReportResponse reportResponse = ReportResponse.builder()
|
||||
.quizesetId(quizSet.getId())
|
||||
.userId(testuser.getId())
|
||||
@ -100,4 +106,5 @@ public class ReportServiceImpl implements ReportService {
|
||||
|
||||
return reportResponse;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ spring.datasource.username=${USER_NAME}
|
||||
spring.datasource.password=${USER_PASSWORD}
|
||||
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
|
||||
spring.jpa.database=mysql
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.hibernate.ddl-auto=create
|
||||
spring.jpa.show-sql=true
|
||||
management.endpoints.web.exposure.include=health,info
|
||||
management.endpoint.health.show-details=always
|
||||
|
Loading…
Reference in New Issue
Block a user