From 6f62cf9d52e1d5353be33f1fbf3429b0be456dc7 Mon Sep 17 00:00:00 2001 From: Szymon Szukalski Date: Tue, 23 Jul 2024 16:30:53 +1000 Subject: Implement simple /results/:id/aggregate endpoint and test --- .../markr/controller/TestResultsController.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/main/java/com/stileeducation/markr/controller') diff --git a/src/main/java/com/stileeducation/markr/controller/TestResultsController.java b/src/main/java/com/stileeducation/markr/controller/TestResultsController.java index b1a5e63..f5f8a44 100644 --- a/src/main/java/com/stileeducation/markr/controller/TestResultsController.java +++ b/src/main/java/com/stileeducation/markr/controller/TestResultsController.java @@ -1,19 +1,18 @@ package com.stileeducation.markr.controller; +import com.stileeducation.markr.dto.AggregatedTestResultsDTO; import com.stileeducation.markr.dto.MCQTestResultsDTO; import com.stileeducation.markr.service.TestResultsService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/") public class TestResultsController { public static final String IMPORT_ENDPOINT = "/import"; + public static final String AGGREGATE_ENDPOINT = "/results/{test-id}/aggregate"; private final TestResultsService testResultsService; @@ -25,8 +24,12 @@ public class TestResultsController { @PostMapping(value = IMPORT_ENDPOINT, consumes = "application/xml", produces = "application/json") public ResponseEntity handleXmlRequest(@RequestBody MCQTestResultsDTO testResults) { testResultsService.importTestResults(testResults); - 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); + } + } -- cgit v1.2.3