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
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
private String userAnswer;
|
private String userAnswer;
|
||||||
private boolean isCorrect;
|
private boolean isCorrect;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name= "report_id")
|
@JoinColumn(name = "report_id")
|
||||||
private Report report;
|
private Report report;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name= "quiz_id")
|
@JoinColumn(name = "quiz_id")
|
||||||
private Quiz quiz;
|
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.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.entity.dto.ReportRequset;
|
||||||
|
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;
|
||||||
import com.edufocus.edufocus.user.model.repository.UserRepository;
|
import com.edufocus.edufocus.user.model.repository.UserRepository;
|
||||||
@ -18,6 +19,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -32,6 +34,7 @@ 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 AnswerService answerService;
|
private final AnswerService answerService;
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
@ -39,56 +42,59 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
@Override
|
@Override
|
||||||
public ReportResponse grading(ReportRequset reportRequset) throws SQLException {
|
public ReportResponse grading(ReportRequset reportRequset) throws SQLException {
|
||||||
|
|
||||||
|
|
||||||
QuizSet quizSet = quizSetService.findQuizSet(reportRequset.getQuizsetId());
|
QuizSet quizSet = quizSetService.findQuizSet(reportRequset.getQuizsetId());
|
||||||
System.out.println(quizSet.toString());
|
|
||||||
List<Quiz> quizList = quizSet.getQuizzes();
|
List<Quiz> quizList = quizSet.getQuizzes();
|
||||||
List<AnswerInput> answerInputList = reportRequset.getAnswerInputList();
|
List<AnswerInput> answerInputList = reportRequset.getAnswerInputList();
|
||||||
|
|
||||||
Report report = new Report();
|
List<Answer> answerList = new ArrayList<>();
|
||||||
|
|
||||||
Long reportNum = report.getId();
|
|
||||||
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(reportRequset.getUserId()).orElse(null);
|
||||||
|
|
||||||
for (Quiz quiz : quizList) {
|
for (int idx = 0; idx < answerInputList.size(); idx++) {
|
||||||
for (AnswerInput answerInput : answerInputList) {
|
Quiz quiz = quizList.get(idx);
|
||||||
if (quiz.getId() == answerInput.getAnswerinputID()) {
|
AnswerInput inputAnswer = answerInputList.get(idx);
|
||||||
|
Answer answer;
|
||||||
if (quiz.getAnswer().equals(answerInput.getAnswer())) {
|
if (quiz.getAnswer().equals(inputAnswer.getAnswer())) {
|
||||||
correctCount++;
|
correctCount++;
|
||||||
|
answer = Answer.builder()
|
||||||
Answer answer = Answer.builder()
|
.userAnswer(inputAnswer.getAnswer())
|
||||||
.userAnswer(answerInput.getAnswer())
|
.isCorrect(true)
|
||||||
.isCorrect(true)
|
.report(null)
|
||||||
.report(report)
|
.quiz(quiz)
|
||||||
.quiz(quiz)
|
.build();
|
||||||
.build();
|
} else {
|
||||||
|
answer = Answer.builder()
|
||||||
} else {
|
.userAnswer(inputAnswer.getAnswer())
|
||||||
Answer answer = Answer.builder()
|
.isCorrect(false)
|
||||||
.userAnswer(answerInput.getAnswer())
|
.report(null)
|
||||||
.isCorrect(false)
|
.quiz(quiz)
|
||||||
.report(report)
|
.build();
|
||||||
.quiz(quiz)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
answerList.add(answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
report = Report.builder()
|
|
||||||
|
Report report = Report.builder()
|
||||||
.user(testuser)
|
.user(testuser)
|
||||||
.quizSet(quizSet)
|
.quizSet(quizSet)
|
||||||
.allCount(allCount)
|
.allCount(allCount)
|
||||||
.correctCount(correctCount)
|
.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()
|
ReportResponse reportResponse = ReportResponse.builder()
|
||||||
.quizesetId(quizSet.getId())
|
.quizesetId(quizSet.getId())
|
||||||
.userId(testuser.getId())
|
.userId(testuser.getId())
|
||||||
@ -100,4 +106,5 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
|
|
||||||
return reportResponse;
|
return reportResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ spring.datasource.username=${USER_NAME}
|
|||||||
spring.datasource.password=${USER_PASSWORD}
|
spring.datasource.password=${USER_PASSWORD}
|
||||||
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
|
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
|
||||||
spring.jpa.database=mysql
|
spring.jpa.database=mysql
|
||||||
spring.jpa.hibernate.ddl-auto=update
|
spring.jpa.hibernate.ddl-auto=create
|
||||||
spring.jpa.show-sql=true
|
spring.jpa.show-sql=true
|
||||||
management.endpoints.web.exposure.include=health,info
|
management.endpoints.web.exposure.include=health,info
|
||||||
management.endpoint.health.show-details=always
|
management.endpoint.health.show-details=always
|
||||||
|
Loading…
Reference in New Issue
Block a user