diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-07-25 12:10:25 +1000 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-07-25 12:10:25 +1000 |
| commit | 98f6bffd91a83fd2fee5481255604b302d59dd59 (patch) | |
| tree | f54d0292c97dc250f7b5c02b4db518a85ba6f713 /src/main/java/com/stileeducation/markr/controller/TestResultsController.java | |
| parent | 7429ce2c63f467cc6e0f742c644b53dcdd5a635b (diff) | |
Fix formatting and add some clarifying comments
Diffstat (limited to 'src/main/java/com/stileeducation/markr/controller/TestResultsController.java')
| -rw-r--r-- | src/main/java/com/stileeducation/markr/controller/TestResultsController.java | 129 |
1 files changed, 67 insertions, 62 deletions
diff --git a/src/main/java/com/stileeducation/markr/controller/TestResultsController.java b/src/main/java/com/stileeducation/markr/controller/TestResultsController.java index c69492d..1376ecb 100644 --- a/src/main/java/com/stileeducation/markr/controller/TestResultsController.java +++ b/src/main/java/com/stileeducation/markr/controller/TestResultsController.java @@ -20,70 +20,75 @@ import org.springframework.web.bind.annotation.*; @RequestMapping("/") public class TestResultsController { - public static final String IMPORT_ENDPOINT = "/import"; - public static final String AGGREGATE_ENDPOINT = "/results/{test-id}/aggregate"; - - @Autowired - private StudentService studentService; - - @Autowired - private TestService testService; - - @Autowired - private TestResultsService testResultsService; - - @Autowired - private TestRepository testRepository; - - @Autowired - private TestResultRepository testResultRepository; - - public TestResultsController(TestResultsService testResultsService) { - this.testResultsService = testResultsService; - } - - // TODO consider return value - @PostMapping(value = IMPORT_ENDPOINT, consumes = "text/xml+markr", produces = "application/json") - public ResponseEntity<Void> handleXmlRequest(@RequestBody MCQTestResultsDTO testResults) { - - for (MCQTestResultDTO mcqTestResult : testResults.getMcqTestResults()) { - Student student = studentService - .findOrCreateStudent( - mcqTestResult.getFirstName(), - mcqTestResult.getLastName(), - mcqTestResult.getStudentNumber()); - - Test test = testService - .findOrCreateTest( - mcqTestResult.getTestId(), - mcqTestResult.getSummaryMarks().getAvailable()); - - if (test.getMarksAvailable() < mcqTestResult.getSummaryMarks().getAvailable()) { - test.setMarksAvailable(mcqTestResult.getSummaryMarks().getAvailable()); - testRepository.save(test); - } - - // Some edge cases to consider - // obtained is higher than available (assumption?) - - TestResult testResult = testResultsService - .findOrCreateTestResult( - student.getId(), - test.getId(), - mcqTestResult.getSummaryMarks().getObtained()); - - if (testResult.getMarksAwarded() < mcqTestResult.getSummaryMarks().getObtained()) { - testResult.setMarksAwarded(mcqTestResult.getSummaryMarks().getObtained()); - testResultRepository.save(testResult); - } + public static final String IMPORT_ENDPOINT = "/import"; + public static final String AGGREGATE_ENDPOINT = "/results/{test-id}/aggregate"; + + @Autowired + private StudentService studentService; + + @Autowired + private TestService testService; + + @Autowired + private TestResultsService testResultsService; + + @Autowired + private TestRepository testRepository; + + @Autowired + private TestResultRepository testResultRepository; + + public TestResultsController(TestResultsService testResultsService) { + this.testResultsService = testResultsService; } - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } + // TODO consider return value + @PostMapping( + value = IMPORT_ENDPOINT, + consumes = "text/xml+markr", + produces = "application/json") + public ResponseEntity<Void> handleXmlRequest(@RequestBody MCQTestResultsDTO testResults) { + + for (MCQTestResultDTO mcqTestResult : testResults.getMcqTestResults()) { + Student student = studentService + .findOrCreateStudent( + mcqTestResult.getFirstName(), + mcqTestResult.getLastName(), + mcqTestResult.getStudentNumber()); + + Test test = testService + .findOrCreateTest( + mcqTestResult.getTestId(), + mcqTestResult.getSummaryMarks().getAvailable()); + + if (test.getMarksAvailable() < mcqTestResult.getSummaryMarks().getAvailable()) { + test.setMarksAvailable(mcqTestResult.getSummaryMarks().getAvailable()); + testRepository.save(test); + } + + // Some edge cases to consider + // obtained is higher than available (assumption?) + + TestResult testResult = testResultsService + .findOrCreateTestResult( + student.getId(), + test.getId(), + mcqTestResult.getSummaryMarks().getObtained()); + + if (testResult.getMarksAwarded() < mcqTestResult.getSummaryMarks().getObtained()) { + testResult.setMarksAwarded(mcqTestResult.getSummaryMarks().getObtained()); + testResultRepository.save(testResult); + } + } + + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } - @GetMapping(value = AGGREGATE_ENDPOINT, produces = "application/json") - public AggregatedTestResultsDTO getAggregatedResults(@PathVariable("test-id") String testId) { - return testResultsService.aggregateTestResults(testId); - } + @GetMapping( + value = AGGREGATE_ENDPOINT, + produces = "application/json") + public AggregatedTestResultsDTO getAggregatedResults(@PathVariable("test-id") String testId) { + return testResultsService.aggregateTestResults(testId); + } } |
