diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-07-26 11:43:56 +1000 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-07-26 11:43:56 +1000 |
| commit | 1abae6d1e41659ebe3230352c58e0cf0550f19eb (patch) | |
| tree | d8a53520348ef4079530db2e23354b3fc04b4814 /src/main/java/com/stileeducation/markr/service/TestResultsService.java | |
| parent | 40fd0f10181909719f2541d62965dbcbc8e91078 (diff) | |
Add test not found handling to /aggregate endpoint
Diffstat (limited to 'src/main/java/com/stileeducation/markr/service/TestResultsService.java')
| -rw-r--r-- | src/main/java/com/stileeducation/markr/service/TestResultsService.java | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/main/java/com/stileeducation/markr/service/TestResultsService.java b/src/main/java/com/stileeducation/markr/service/TestResultsService.java index 8dba13f..a06400e 100644 --- a/src/main/java/com/stileeducation/markr/service/TestResultsService.java +++ b/src/main/java/com/stileeducation/markr/service/TestResultsService.java @@ -7,6 +7,7 @@ import com.stileeducation.markr.dto.MCQTestResultsDTO; import com.stileeducation.markr.entity.Student; import com.stileeducation.markr.entity.Test; import com.stileeducation.markr.entity.TestResult; +import com.stileeducation.markr.exception.TestNotFoundException; import com.stileeducation.markr.repository.TestResultRepository; import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; import org.apache.commons.math3.stat.descriptive.rank.Percentile; @@ -43,12 +44,13 @@ public class TestResultsService { public AggregateResponseDTO aggregateTestResults(String testId) { AggregateResponseDTO aggregateResponseDTO = new AggregateResponseDTO(); - testService.findTest(testId).ifPresent(test -> { - List<TestResult> testResults = findAllByTestId(testId); - if (!testResults.isEmpty()) { - populateAggregateResponse(aggregateResponseDTO, test, testResults); - } - }); + Test test = testService.findTest(testId) + .orElseThrow(() -> new TestNotFoundException("Test with ID " + testId + " not found")); + + List<TestResult> testResults = findAllByTestId(testId); + if (!testResults.isEmpty()) { + populateAggregateResponse(aggregateResponseDTO, test, testResults); + } return aggregateResponseDTO; } |
