diff --git a/doc/web_app_flowchart/web_app_flowchart.drawio b/doc/web_app_flowchart/web_app_flowchart.drawio
index d603bf4..e9a0477 100644
--- a/doc/web_app_flowchart/web_app_flowchart.drawio
+++ b/doc/web_app_flowchart/web_app_flowchart.drawio
@@ -1,6 +1,6 @@
-
+
@@ -67,12 +67,24 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/doc/web_app_flowchart/web_app_flowchart.jpg b/doc/web_app_flowchart/web_app_flowchart.jpg
index 51a09de..662dfb3 100644
Binary files a/doc/web_app_flowchart/web_app_flowchart.jpg and b/doc/web_app_flowchart/web_app_flowchart.jpg differ
diff --git a/src/main/java/com/czechtutor/controller/ApplicationController.java b/src/main/java/com/czechtutor/controller/ApplicationController.java
index 3ae11ef..b501983 100644
--- a/src/main/java/com/czechtutor/controller/ApplicationController.java
+++ b/src/main/java/com/czechtutor/controller/ApplicationController.java
@@ -153,7 +153,7 @@ public String createLesson(@ModelAttribute LessonModel lessonModel) {
lessonService.save(lessonModel);
// redirect to view
String path = String.valueOf(lessonModel.getLessonId());
- String view = "/lesson/" + path;
+ String view = "/newLessonQuestion/" + path;
logger.info(lessonModel.getLessonPayload());
return "redirect:" + view;
}
@@ -165,43 +165,20 @@ public String createLesson(@ModelAttribute LessonModel lessonModel) {
* @param lessonId the generated lesson id path variable
* @return redirects to the lesson template with the generated lesson id
*/
- @GetMapping(value = "/lesson/{lessonId}")
- public String createQuestion(@PathVariable("lessonId") Integer lessonId) {
- // check NQuestions for lessonId against database
- Integer nQuestions = lessonService.get(lessonId).getNQuestions();
- Integer nLessonQuestions = questionService.findByLessonId(lessonId).size();
- if (nLessonQuestions < nQuestions) {
- logger.info("~~~~~ Creating question.");
- // generate a question
- LessonModel lessonModel = lessonService.get(lessonId);
- QuestionModel questionModel = questionService.create(lessonModel, null);
- questionService.save(questionModel);
- Integer questionId = questionModel.getQuestionId();
- // redirect to view
- String path = String.valueOf(lessonId) + "/" + String.valueOf(questionId);
- String view = "/lesson/" + path;
- logger.info(view);
- logger.info(questionModel.getQuestionPayload());
- return "redirect:" + view;
- } else {
- logger.info("~~~~~ Creating result.");
- // define decimal formatter
- DecimalFormat decimalFormatter = new DecimalFormat("#.##");
- decimalFormatter.setRoundingMode(RoundingMode.HALF_EVEN);
- // generate the results of the lesson
- ArrayList lessonAnswers = answerService.findByLessonId(lessonId);
- Integer nCorrect = resultService.countTotalCorrect(lessonAnswers);
- Float score = Float.valueOf(decimalFormatter.format(Float.valueOf(nCorrect) / Float.valueOf(nQuestions) * 100));
- // create a result
- ResultModel resultModel = resultService.create(lessonId, nCorrect, score);
- resultService.save(resultModel);
- // redirect to view
- String path = String.valueOf(lessonId);
- String view = "/result/" + path;
- logger.info(view);
- logger.info(resultModel.getResultPayload());
- return "redirect:" + view;
- }
+ @GetMapping(value = "/newLessonQuestion/{lessonId}")
+ public String createLessonQuestion(@PathVariable("lessonId") Integer lessonId) {
+ logger.info("~~~~~ Creating question.");
+ // generate a question
+ LessonModel lessonModel = lessonService.get(lessonId);
+ QuestionModel questionModel = questionService.create(lessonModel, null);
+ questionService.save(questionModel);
+ Integer lessonQuestionId = questionModel.getLessonQuestionId();
+ // redirect to view
+ String path = String.valueOf(lessonId) + "/" + String.valueOf(lessonQuestionId);
+ String view = "/lesson/" + path;
+ logger.info(view);
+ logger.info(questionModel.getQuestionPayload());
+ return "redirect:" + view;
}
/**
@@ -210,16 +187,17 @@ public String createQuestion(@PathVariable("lessonId") Integer lessonId) {
* id
*
* @param lessonId the generated lesson id path variable
- * @param questionId the generated question id path variable
+ * @param lessonQuestionId the generated lesson question id path variable
* @param model the Model ui object for populating the lesson template with
* Thymeleaf
* @return the lesson template for the given lesson id and question id
*/
- @GetMapping(value = "/lesson/{lessonId}/{questionId}")
- public String getLessonPage(@PathVariable("lessonId") Integer lessonId, @PathVariable("questionId") Integer questionId, Model model) {
+ @GetMapping(value = "/lesson/{lessonId}/{lessonQuestionId}")
+ public String getLessonPage(@PathVariable("lessonId") Integer lessonId, @PathVariable("lessonQuestionId") Integer lessonQuestionId, Model model) {
logger.info("~~~~~ Redirecting to lesson.");
- QuestionModel questionModel = questionService.get(questionId);
- String path = String.valueOf(lessonId) + "/" + String.valueOf(questionId);
+ // pull lesson model for lesson id and lesson question id
+ QuestionModel questionModel = questionService.getQuestionByLessonQuestionIds(lessonId, lessonQuestionId);
+ String path = String.valueOf(lessonId) + "/" + String.valueOf(lessonQuestionId);
model.addAttribute("questionModel", questionModel);
model.addAttribute("answerModel", new AnswerModel());
model.addAttribute("path", path);
@@ -232,25 +210,75 @@ public String getLessonPage(@PathVariable("lessonId") Integer lessonId, @PathVar
* Posts user input from the lesson template page
*
* @param lessonId the generated lesson id path variable
- * @param questionId the generated question id path variable
+ * @param lessonQuestionId the generated lesson question id path variable
* @param answerModel the completed answer model form
* @return redirects to the lesson template with the lesson id
*/
- @PostMapping(value = "/lesson/{lessonId}/{questionId}")
- public String createAnswer(@PathVariable("lessonId") Integer lessonId, @PathVariable("questionId") Integer questionId, @ModelAttribute AnswerModel answerModel) {
+ @PostMapping(value = "/lesson/{lessonId}/{lessonQuestionId}")
+ public String createAnswer(@PathVariable("lessonId") Integer lessonId, @PathVariable("lessonQuestionId") Integer lessonQuestionId, @ModelAttribute AnswerModel answerModel) {
logger.info("~~~~~ Creating answer");
+ // pull lesson model for lesson id and lesson question id
+ QuestionModel questionModel = questionService.getQuestionByLessonQuestionIds(lessonId, lessonQuestionId);
// generate a answer
- QuestionModel questionModel = questionService.get(questionId);
+ answerModel.setQuestionId(questionModel.getQuestionId());
answerModel.setCorrect(answerService.isCorrect(questionModel, answerModel));
answerModel.setDateTime(LocalDateTime.now());
answerModel.setDateTimeHash(utilityService.MD5DateTimeHash(answerModel.getDateTime()));
+ // check if answer already exists for the question id
+ if (answerService.existsByQuestionId(questionModel.getQuestionId())) {
+ // if ot does assign answer id and overwrite existing result
+ answerModel.setAnswerId(answerService.findByQuestionId(questionModel.getQuestionId()).getAnswerId());
+ }
answerService.save(answerModel);
- // redirect to view
- String path = String.valueOf(lessonId);
- String view = "/lesson/" + path;
- logger.info(view);
- logger.info(answerModel.getAnswerPayload());
- return "redirect:" + view;
+ // check NQuestions for lessonId against database
+ Integer nQuestions = lessonService.get(lessonId).getNQuestions();
+ Integer nLessonQuestions = questionService.findByLessonId(lessonId).size();
+ // if the lesson question id is greater than the number of available questions, and also less than the total required questions
+ if (lessonQuestionId >= nLessonQuestions && lessonQuestionId < nQuestions) {
+ logger.info("~~~~~ Redirecting to new question.");
+ // redirect to new lesson question view
+ String path = String.valueOf(lessonId);
+ String view = "/newLessonQuestion/" + path;
+ logger.info(view);
+ logger.info(answerModel.getAnswerPayload());
+ return "redirect:" + view;
+ // otherwise if the lesson question id is less than the number of available question, and also less the total required questions
+ } else if (lessonQuestionId < nQuestions && lessonQuestionId < nQuestions) {
+ logger.info("~~~~~ Redirecting to next question.");
+ // redirect to the the new question in the lesson view
+ Integer nextLessonQuestionId = lessonQuestionId + 1;
+ QuestionModel nextQuestionModel = questionService.getQuestionByLessonQuestionIds(lessonId, nextLessonQuestionId);
+ // redirect to view
+ String path = String.valueOf(lessonId) + "/" + String.valueOf(lessonQuestionId + 1);
+ String view = "/lesson/" + path;
+ logger.info(view);
+ logger.info(nextQuestionModel.getQuestionPayload());
+ return "redirect:" + view;
+ // otherwise all questions have been completed and redirect to results view
+ } else {
+ logger.info("~~~~~ Creating result.");
+ // define decimal formatter
+ DecimalFormat decimalFormatter = new DecimalFormat("#.##");
+ decimalFormatter.setRoundingMode(RoundingMode.HALF_EVEN);
+ // generate the results of the lesson
+ ArrayList lessonAnswers = answerService.findByLessonId(lessonId);
+ Integer nCorrect = resultService.countTotalCorrect(lessonAnswers);
+ Float score = Float.valueOf(decimalFormatter.format(Float.valueOf(nCorrect) / Float.valueOf(nQuestions) * 100));
+ // create a result
+ ResultModel resultModel = resultService.create(lessonId, nCorrect, score);
+ // check if an existing results model already exists for the lesson id
+ if (resultService.existsByLessonId(lessonId)) {
+ // overwrite the result id with the result id from the result model corresponding to the existing lesson id
+ resultModel.setResultId(resultService.findByLessonId(lessonId).getResultId());
+ }
+ resultService.save(resultModel);
+ // redirect to view
+ String path = String.valueOf(lessonId);
+ String view = "/result/" + path;
+ logger.info(view);
+ logger.info(resultModel.getResultPayload());
+ return "redirect:" + view;
+ }
}
/**
@@ -270,11 +298,21 @@ public String getResultPage(@PathVariable("lessonId") Integer lessonId, Model mo
LessonModel lessonModel = lessonService.get(lessonId);
// create results messages
ResultModel resultModel = resultService.findByLessonId(lessonId);
- String scoreMessage = "Score: " + String.valueOf(resultModel.getScore()) + "%";
- String nCorrectMessage = "Answered " + String.valueOf(resultModel.getNCorrect()) + " out of " + String.valueOf(nQuestions) + " questions correctly";
+ String scoreMessage = "This lesson is incomplete.";
+ String nCorrectMessage = "Complete using 'Retry Lesson' below.";
+ if (resultService.existsByLessonId(lessonId)) {
+ scoreMessage = "Score: " + String.valueOf(resultModel.getScore()) + "%";
+ nCorrectMessage = "Answered " + String.valueOf(resultModel.getNCorrect()) + " out of " + String.valueOf(nQuestions) + " questions correctly";
+ }
String path = String.valueOf(lessonId);
// generate combined lesson questions and answers
ArrayList lessonQuestionsAnswers = lessonQuestionAnswerService.createLessonSummary(lessonModel);
+ // map solution to null if answers have not been provided
+ for (LessonQuestionAnswer lessonQuestionAnswer : lessonQuestionsAnswers) {
+ if (lessonQuestionAnswer.getAnswerId() == null) {
+ lessonQuestionAnswer.setSolution(null);
+ }
+ }
// add attributes to model object
model.addAttribute("scoreMessage", scoreMessage);
model.addAttribute("nCorrectMessage", nCorrectMessage);
@@ -284,19 +322,6 @@ public String getResultPage(@PathVariable("lessonId") Integer lessonId, Model mo
return "result";
}
- /**
- *
- * Posts user input from the result template page
- *
- * @param lessonId the generated lesson id path variable
- * @return redirects to the home template
- */
- @PostMapping(value = "/resultHome/{lessonId}")
- public String redirectResulttoHome(@PathVariable("lessonId") Integer lessonId) {
- logger.info("~~~~~ Redirecting home.");
- return "redirect:/home";
- }
-
/**
*
* Posts user input from the result template page
@@ -305,9 +330,9 @@ public String redirectResulttoHome(@PathVariable("lessonId") Integer lessonId) {
* @return redirects to the lesson template with the same lesson
* configurations
*/
- @PostMapping(value = "/resultRedo/{lessonId}")
- public String redirectResulttoLesson(@PathVariable("lessonId") Integer lessonId) {
- logger.info("~~~~~ Creating lesson");
+ @PostMapping(value = "/resultNew/{lessonId}")
+ public String redirectResultToNewLesson(@PathVariable("lessonId") Integer lessonId) {
+ logger.info("~~~~~ Creating new lesson");
// generate a new lesson from the current lesson
LessonModel currentLessonModel = lessonService.get(lessonId);
LessonModel newLessonModel = new LessonModel();
@@ -321,9 +346,29 @@ public String redirectResulttoLesson(@PathVariable("lessonId") Integer lessonId)
lessonService.save(newLessonModel);
// redirect to view
String path = String.valueOf(newLessonModel.getLessonId());
- String view = "/lesson/" + path;
+ String view = "/newLessonQuestion/" + path;
logger.info(newLessonModel.getLessonPayload());
return "redirect:" + view;
}
+ /**
+ *
+ * Posts user input from the result template page
+ *
+ * @param lessonId the generated lesson id path variable
+ * @return redirects to the lesson template with the same lesson
+ * configurations
+ */
+ @PostMapping(value = "/resultRetry/{lessonId}")
+ public String redirectResultToRetryLesson(@PathVariable("lessonId") Integer lessonId) {
+ logger.info("~~~~~ Retrying lesson");
+ // generate a new lesson from the current lesson
+ LessonModel currentLessonModel = lessonService.get(lessonId);
+ // redirect to view
+ String path = String.valueOf(lessonId) + "/1";
+ String view = "/lesson/" + path;
+ logger.info(currentLessonModel.getLessonPayload());
+ return "redirect:" + view;
+ }
+
}
diff --git a/src/main/java/com/czechtutor/model/QuestionModel.java b/src/main/java/com/czechtutor/model/QuestionModel.java
index 2e6034a..a1a5e16 100644
--- a/src/main/java/com/czechtutor/model/QuestionModel.java
+++ b/src/main/java/com/czechtutor/model/QuestionModel.java
@@ -18,6 +18,7 @@ public class QuestionModel {
@Id
private Integer questionId;
private Integer lessonId;
+ private Integer lessonQuestionId;
private String phrase;
private String option1;
private String option2;
@@ -38,6 +39,7 @@ public void set(HashMap payload) {
// set the class objects
//this.questionId = (Integer) payload.get("questionId");
this.lessonId = (Integer) payload.get("lessonId");
+ this.lessonQuestionId = (Integer) payload.get("lessonQuestionId");
this.phrase = (String) payload.get("phrase");
this.option1 = (String) payload.get("option1");
this.option2 = (String) payload.get("option2");
@@ -60,6 +62,7 @@ public HashMap getQuestionPayload() {
HashMap questionPayload = new HashMap<>();
questionPayload.put("questionId", questionId);
questionPayload.put("lessonId", lessonId);
+ questionPayload.put("lessonQuestionId", lessonQuestionId);
questionPayload.put("phrase", phrase);
questionPayload.put("option1", option1);
questionPayload.put("option2", option2);
@@ -93,9 +96,9 @@ public void setQuestionId(Integer questionId) {
/**
*
- * Gets the question lesson id attribute of a question model
+ * Gets the lesson id attribute of a question model
*
- * @return the question lesson id attribute
+ * @return the lesson id attribute
*/
public Integer getLessonId() {
return lessonId;
@@ -103,14 +106,35 @@ public Integer getLessonId() {
/**
*
- * Sets the question lesson id attribute of a question model
+ * Sets the lesson id attribute of a question model
*
- * @param lessonId the question lesson id attribute
+ * @param lessonId the lesson id attribute
*/
public void setLessonId(Integer lessonId) {
this.lessonId = lessonId;
}
+
+ /**
+ *
+ * Gets the question lesson id attribute of a question model
+ *
+ * @return the question lesson id attribute
+ */
+ public Integer getLessonQuestionId() {
+ return lessonQuestionId;
+ }
+
+ /**
+ *
+ * Sets the question lesson id attribute of a question model
+ *
+ * @param lessonId the question lesson id attribute
+ */
+ public void setQuestionLessonId(Integer lessonQuestionId) {
+ this.lessonQuestionId = lessonQuestionId;
+ }
+
/**
*
* Gets the question phrase attribute of a question model
diff --git a/src/main/java/com/czechtutor/repository/crud/AnswerCrudRepository.java b/src/main/java/com/czechtutor/repository/crud/AnswerCrudRepository.java
index 3909c0c..224de0d 100644
--- a/src/main/java/com/czechtutor/repository/crud/AnswerCrudRepository.java
+++ b/src/main/java/com/czechtutor/repository/crud/AnswerCrudRepository.java
@@ -19,9 +19,27 @@ public interface AnswerCrudRepository extends CrudRepository
* Finds all answer models with a specified lesson id as an array list
*
- * @param LessonId the lesson id to find by
+ * @param lessonId the lesson id to find by
* @return the answer models as an array list
*/
- ArrayList findByLessonId(String LessonId);
+ ArrayList findByLessonId(String lessonId);
+
+ /**
+ *
+ * Finds a answer model by a question id
+ *
+ * @param questionId the question id to find an answer by
+ * @return the answer model
+ */
+ AnswerModel findByQuestionId(String questionId);
+
+ /**
+ *
+ * Determines if an answer model exists for a question id
+ *
+ * @param questionId the question id to find if answer exist for
+ * @return whether the answer model exists
+ */
+ Boolean existsByQuestionId(String questionId);
}
diff --git a/src/main/java/com/czechtutor/repository/crud/CesCrudRepository.java b/src/main/java/com/czechtutor/repository/crud/CesCrudRepository.java
index 2612238..20dc00e 100644
--- a/src/main/java/com/czechtutor/repository/crud/CesCrudRepository.java
+++ b/src/main/java/com/czechtutor/repository/crud/CesCrudRepository.java
@@ -19,9 +19,9 @@ public interface CesCrudRepository extends CrudRepository {
*
* Finds all ces models with a specified level as an array list
*
- * @param Level the Level to find by
+ * @param level the Level to find by
* @return the ces models as an array list
*/
- ArrayList findByLevel(String Level);
+ ArrayList findByLevel(String level);
}
diff --git a/src/main/java/com/czechtutor/repository/crud/QuestionCrudRepository.java b/src/main/java/com/czechtutor/repository/crud/QuestionCrudRepository.java
index ce57895..b86bc9e 100644
--- a/src/main/java/com/czechtutor/repository/crud/QuestionCrudRepository.java
+++ b/src/main/java/com/czechtutor/repository/crud/QuestionCrudRepository.java
@@ -2,7 +2,9 @@
import java.util.ArrayList;
+import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.repository.query.Param;
import com.czechtutor.model.QuestionModel;
@@ -19,9 +21,16 @@ public interface QuestionCrudRepository extends CrudRepository
* Finds all question models with a specified lesson id as an array list
*
- * @param LessonId the lesson id to find by
+ * @param lessonId the lesson id to find by
* @return the question models as an array list
*/
- ArrayList findByLessonId(String LessonId);
+ ArrayList findByLessonId(String lessonId);
+
+ public static final String GET_QUESTION_BY_LESSON_QUESTION_IDS_QUERY = """
+ select * from questions where lesson_id = :#{#lessonId.intValue()} and lesson_question_id = :#{#LessonQuestionId.intValue()}
+ """;
+
+ @Query(GET_QUESTION_BY_LESSON_QUESTION_IDS_QUERY)
+ QuestionModel getQuestionByLessonQuestionIds(@Param("lessonId") Integer lessonId, @Param("LessonQuestionId") Integer LessonQuestionId);
}
diff --git a/src/main/java/com/czechtutor/repository/crud/ResultCrudRepository.java b/src/main/java/com/czechtutor/repository/crud/ResultCrudRepository.java
index ea12d35..b18a9b8 100644
--- a/src/main/java/com/czechtutor/repository/crud/ResultCrudRepository.java
+++ b/src/main/java/com/czechtutor/repository/crud/ResultCrudRepository.java
@@ -17,9 +17,18 @@ public interface ResultCrudRepository extends CrudRepository
* Finds a result model with a specified lesson id
*
- * @param LessonId the lesson id to find by
+ * @param lessonId the lesson id to find by
* @return the result model
*/
- ResultModel findByLessonId(String LessonId);
+ ResultModel findByLessonId(String lessonId);
+
+ /**
+ *
+ * Determines if a results model exists for a lesson id
+ *
+ * @param lessonId the lesson id to find if results exist for
+ * @return whether the result model exists
+ */
+ Boolean existsByLessonId(String lessonId);
}
diff --git a/src/main/java/com/czechtutor/repository/crud/custom/LessonQuestionAnswerCrudRepository.java b/src/main/java/com/czechtutor/repository/crud/custom/LessonQuestionAnswerCrudRepository.java
index d84c1fa..979b254 100644
--- a/src/main/java/com/czechtutor/repository/crud/custom/LessonQuestionAnswerCrudRepository.java
+++ b/src/main/java/com/czechtutor/repository/crud/custom/LessonQuestionAnswerCrudRepository.java
@@ -24,9 +24,10 @@ public interface LessonQuestionAnswerCrudRepository extends CrudRepository findByLessonId(Integer lessonId) {
return answerCrudRepository.findByLessonId(String.valueOf(lessonId));
}
+ /**
+ *
+ * Determines if an answer already exists by an answer id
+ *
+ * @param answerId the answer id to find if exists
+ * @return whether the answer model exists or not
+ */
+ public Boolean existsById(Integer answerId) {
+ return answerCrudRepository.existsById(answerId);
+ }
+
+ /**
+ *
+ * Finds a answer model by a question id
+ *
+ * @param questionId the question id to find an answer by
+ * @return the answer model
+ */
+ public AnswerModel findByQuestionId(Integer questionId) {
+ return answerCrudRepository.findByQuestionId(String.valueOf(questionId));
+ }
+
+ /**
+ *
+ * Determines if an answer already exists by a question id
+ *
+ * @param questionId the question id to find if an answer exists for
+ * @return whether the answer model exists or not
+ */
+ public Boolean existsByQuestionId(Integer questionId) {
+ return answerCrudRepository.existsByQuestionId(String.valueOf(questionId));
+ }
+
}
diff --git a/src/main/java/com/czechtutor/service/QuestionService.java b/src/main/java/com/czechtutor/service/QuestionService.java
index df160c2..956acf7 100644
--- a/src/main/java/com/czechtutor/service/QuestionService.java
+++ b/src/main/java/com/czechtutor/service/QuestionService.java
@@ -97,6 +97,7 @@ public QuestionModel create(LessonModel lessonModel, Long randomSeed) {
// create a question
QuestionModel questionModel = new QuestionModel();
questionModel.setLessonId(lessonModel.getLessonId());
+ questionModel.setQuestionLessonId(questionCrudRepository.findByLessonId(String.valueOf(lessonModel.getLessonId())).size()+1);
questionModel.setPhrase((String) cesModelArray.get(phaseIndex).getCesPayload().get(lessonModel.getFromLanguage()));
questionModel.setOption1(optionsArray.get(0));
questionModel.setOption2(optionsArray.get(1));
@@ -118,4 +119,16 @@ public QuestionModel create(LessonModel lessonModel, Long randomSeed) {
public ArrayList findByLessonId(Integer lessonId) {
return questionCrudRepository.findByLessonId(String.valueOf(lessonId));
}
+
+ /**
+ *
+ * Retrieves a question model using a lesson id and a question lesson id.
+ *
+ * @param lessonLid the lesson question to find
+ * @param lessonQuestionId the lesson question id to find
+ * @return the question model
+ */
+ public QuestionModel getQuestionByLessonQuestionIds(Integer lessonLid, Integer lessonQuestionId) {
+ return questionCrudRepository.getQuestionByLessonQuestionIds(lessonLid, lessonQuestionId);
+ }
}
diff --git a/src/main/java/com/czechtutor/service/ResultService.java b/src/main/java/com/czechtutor/service/ResultService.java
index 302dce3..a36af3c 100644
--- a/src/main/java/com/czechtutor/service/ResultService.java
+++ b/src/main/java/com/czechtutor/service/ResultService.java
@@ -111,4 +111,26 @@ public ResultModel findByLessonId(Integer lessonId) {
return resultCrudRepository.findByLessonId(String.valueOf(lessonId));
}
+ /**
+ *
+ * Determines if a result already exists by a result id
+ *
+ * @param resultId the result id to find if exists
+ * @return whether the result model exists or not
+ */
+ public Boolean existsById(Integer resultId) {
+ return resultCrudRepository.existsById(resultId);
+ }
+
+ /**
+ *
+ * Determines if a result already exists by a lesson id
+ *
+ * @param lessonId the lesson id to find if results exists for
+ * @return whether the result model exists or not
+ */
+ public Boolean existsByLessonId(Integer lessonId) {
+ return resultCrudRepository.existsByLessonId(String.valueOf(lessonId));
+ }
+
}
diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql
index fb2e3a4..d2c6de8 100644
--- a/src/main/resources/schema.sql
+++ b/src/main/resources/schema.sql
@@ -12,6 +12,7 @@ create table if not exists lessons (
create table if not exists questions (
question_id bigint auto_increment primary key,
lesson_id bigint not null,
+ lesson_question_id tinyint not null,
phrase varchar(255) not null,
option1 varchar(255) not null,
option2 varchar(255) not null,
diff --git a/src/main/resources/static/css/styles.css b/src/main/resources/static/css/styles.css
index 8125076..de5bcef 100644
--- a/src/main/resources/static/css/styles.css
+++ b/src/main/resources/static/css/styles.css
@@ -78,4 +78,9 @@ a {
#lessonNCorrectMessage {
padding-bottom:20px;
+}
+
+#buttonContainer, #newLessonButtonForm, #retryLessonButtonForm, #newLessonButton, #retryLessonButton {
+ display: inline-block;
+ margin-left: 5px;
}
\ No newline at end of file
diff --git a/src/main/resources/templates/result.html b/src/main/resources/templates/result.html
index 57667c0..e383d11 100644
--- a/src/main/resources/templates/result.html
+++ b/src/main/resources/templates/result.html
@@ -21,25 +21,30 @@
| Phrase |
- Solution |
Answer |
+ Solution |
Correct |
|
- |
|
+ |
|
-