summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/stileeducation/markr/controller/TestResultsController.java13
-rw-r--r--src/main/java/com/stileeducation/markr/dto/AggregatedTestResultsDTO.java117
-rw-r--r--src/main/java/com/stileeducation/markr/service/TestResultsService.java3
-rw-r--r--src/main/java/com/stileeducation/markr/service/TestResultsServiceImpl.java16
-rw-r--r--src/test/java/com/stileeducation/markr/controller/TestResultsControllerTest.java28
5 files changed, 171 insertions, 6 deletions
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<Void> 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);
+ }
+
}
diff --git a/src/main/java/com/stileeducation/markr/dto/AggregatedTestResultsDTO.java b/src/main/java/com/stileeducation/markr/dto/AggregatedTestResultsDTO.java
new file mode 100644
index 0000000..f5970c3
--- /dev/null
+++ b/src/main/java/com/stileeducation/markr/dto/AggregatedTestResultsDTO.java
@@ -0,0 +1,117 @@
+package com.stileeducation.markr.dto;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+import java.util.Objects;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class AggregatedTestResultsDTO {
+
+ private double mean;
+ private double stddev;
+ private double min;
+ private double max;
+ private double p25;
+ private double p50;
+ private double p75;
+ private int count;
+
+ // Getters and Setters
+ public double getMean() {
+ return mean;
+ }
+
+ public void setMean(double mean) {
+ this.mean = mean;
+ }
+
+ public double getStddev() {
+ return stddev;
+ }
+
+ public void setStddev(double stddev) {
+ this.stddev = stddev;
+ }
+
+ public double getMin() {
+ return min;
+ }
+
+ public void setMin(double min) {
+ this.min = min;
+ }
+
+ public double getMax() {
+ return max;
+ }
+
+ public void setMax(double max) {
+ this.max = max;
+ }
+
+ public double getP25() {
+ return p25;
+ }
+
+ public void setP25(double p25) {
+ this.p25 = p25;
+ }
+
+ public double getP50() {
+ return p50;
+ }
+
+ public void setP50(double p50) {
+ this.p50 = p50;
+ }
+
+ public double getP75() {
+ return p75;
+ }
+
+ public void setP75(double p75) {
+ this.p75 = p75;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ AggregatedTestResultsDTO that = (AggregatedTestResultsDTO) o;
+ return Double.compare(mean, that.mean) == 0
+ && Double.compare(stddev, that.stddev) == 0
+ && Double.compare(min, that.min) == 0
+ && Double.compare(max, that.max) == 0
+ && Double.compare(p25, that.p25) == 0
+ && Double.compare(p50, that.p50) == 0
+ && Double.compare(p75, that.p75) == 0
+ && count == that.count;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mean, stddev, min, max, p25, p50, p75, count);
+ }
+
+ @Override
+ public String toString() {
+ return "AggregatedTestResultsDTO{" +
+ "mean=" + mean +
+ ", stddev=" + stddev +
+ ", min=" + min +
+ ", max=" + max +
+ ", p25=" + p25 +
+ ", p50=" + p50 +
+ ", p75=" + p75 +
+ ", count=" + count +
+ '}';
+ }
+}
diff --git a/src/main/java/com/stileeducation/markr/service/TestResultsService.java b/src/main/java/com/stileeducation/markr/service/TestResultsService.java
index 810cffa..2740e50 100644
--- a/src/main/java/com/stileeducation/markr/service/TestResultsService.java
+++ b/src/main/java/com/stileeducation/markr/service/TestResultsService.java
@@ -1,7 +1,10 @@
package com.stileeducation.markr.service;
+import com.stileeducation.markr.dto.AggregatedTestResultsDTO;
import com.stileeducation.markr.dto.MCQTestResultsDTO;
public interface TestResultsService {
MCQTestResultsDTO importTestResults(MCQTestResultsDTO mcqTestResults);
+
+ AggregatedTestResultsDTO aggregateTestResults(String testId);
}
diff --git a/src/main/java/com/stileeducation/markr/service/TestResultsServiceImpl.java b/src/main/java/com/stileeducation/markr/service/TestResultsServiceImpl.java
index 0d4cdc9..abb7f18 100644
--- a/src/main/java/com/stileeducation/markr/service/TestResultsServiceImpl.java
+++ b/src/main/java/com/stileeducation/markr/service/TestResultsServiceImpl.java
@@ -1,5 +1,6 @@
package com.stileeducation.markr.service;
+import com.stileeducation.markr.dto.AggregatedTestResultsDTO;
import com.stileeducation.markr.dto.MCQTestResultsDTO;
import org.springframework.stereotype.Service;
@@ -8,8 +9,21 @@ public class TestResultsServiceImpl implements TestResultsService {
@Override
public MCQTestResultsDTO importTestResults(MCQTestResultsDTO testResults) {
- System.out.println(testResults);
return testResults;
}
+ @Override
+ public AggregatedTestResultsDTO aggregateTestResults(String testId) {
+ AggregatedTestResultsDTO results = new AggregatedTestResultsDTO();
+ results.setMean(65.0);
+ results.setStddev(0.0);
+ results.setMin(65.0);
+ results.setMax(65.0);
+ results.setP25(65.0);
+ results.setP50(65.0);
+ results.setP75(65.0);
+ results.setCount(1);
+ return results;
+ }
+
} \ No newline at end of file
diff --git a/src/test/java/com/stileeducation/markr/controller/TestResultsControllerTest.java b/src/test/java/com/stileeducation/markr/controller/TestResultsControllerTest.java
index 4db9008..7d6eb37 100644
--- a/src/test/java/com/stileeducation/markr/controller/TestResultsControllerTest.java
+++ b/src/test/java/com/stileeducation/markr/controller/TestResultsControllerTest.java
@@ -1,6 +1,7 @@
package com.stileeducation.markr.controller;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import com.stileeducation.markr.dto.AggregatedTestResultsDTO;
import com.stileeducation.markr.dto.MCQTestResultsDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -26,16 +27,43 @@ public class TestResultsControllerTest {
@Test
public void testImport() throws Exception {
+ // Given
MCQTestResultsDTO request = new MCQTestResultsDTO();
String requestXml = xmlMapper.writeValueAsString(request);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML);
+ // When
HttpEntity<String> entity = new HttpEntity<>(requestXml, headers);
ResponseEntity<String> response = restTemplate.postForEntity(IMPORT_ENDPOINT, entity, String.class);
+ // Then
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
}
+ @Test
+ public void testAggregate() throws Exception {
+ // Given
+ String testId = "123"; // Example test ID
+ String url = "/results/" + testId + "/aggregate";
+
+ // When
+ ResponseEntity<AggregatedTestResultsDTO> response = restTemplate.getForEntity(url, AggregatedTestResultsDTO.class);
+
+ // Then
+ assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
+
+ AggregatedTestResultsDTO results = response.getBody();
+ assertThat(results).isNotNull();
+ assertThat(results.getMean()).isEqualTo(65.0);
+ assertThat(results.getStddev()).isEqualTo(0.0);
+ assertThat(results.getMin()).isEqualTo(65.0);
+ assertThat(results.getMax()).isEqualTo(65.0);
+ assertThat(results.getP25()).isEqualTo(65.0);
+ assertThat(results.getP50()).isEqualTo(65.0);
+ assertThat(results.getP75()).isEqualTo(65.0);
+ assertThat(results.getCount()).isEqualTo(1);
+ }
+
}