diff --git a/backend/${IMAGE_PATH}/5871dfad-83fc-4665-b2d6-5edeada95134_bono.jpg b/backend/${IMAGE_PATH}/5871dfad-83fc-4665-b2d6-5edeada95134_bono.jpg new file mode 100644 index 0000000..c936434 Binary files /dev/null and b/backend/${IMAGE_PATH}/5871dfad-83fc-4665-b2d6-5edeada95134_bono.jpg differ diff --git a/backend/${IMAGE_PATH}/7da84650-3544-45e3-9677-f8187b8ceb34_bono.jpg b/backend/${IMAGE_PATH}/7da84650-3544-45e3-9677-f8187b8ceb34_bono.jpg new file mode 100644 index 0000000..c936434 Binary files /dev/null and b/backend/${IMAGE_PATH}/7da84650-3544-45e3-9677-f8187b8ceb34_bono.jpg differ diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Answer.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Answer.java index 1437626..929adb0 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Answer.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Answer.java @@ -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; diff --git a/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java index a9e119e..cb5dd56 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java @@ -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 quizList = quizSet.getQuizzes(); List answerInputList = reportRequset.getAnswerInputList(); - Report report = new Report(); + List 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; } + } diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index aa22dc0..68e5d54 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -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