diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-07-25 20:54:41 +1000 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-07-25 20:54:41 +1000 |
| commit | cf4edfcb4bc7d0d02cefa861a95812315f092a66 (patch) | |
| tree | 5a3996a51a7ced388a6d7f4fa5c0d2a84124010e /src/main/java/com/stileeducation | |
| parent | aa9bdd514ab90d0da0391b879255a22c29450e9a (diff) | |
Removed unused variables and switch to constructor injection
Diffstat (limited to 'src/main/java/com/stileeducation')
4 files changed, 22 insertions, 38 deletions
diff --git a/src/main/java/com/stileeducation/markr/controller/TestResultsController.java b/src/main/java/com/stileeducation/markr/controller/TestResultsController.java index f5b6070..9b84e93 100644 --- a/src/main/java/com/stileeducation/markr/controller/TestResultsController.java +++ b/src/main/java/com/stileeducation/markr/controller/TestResultsController.java @@ -3,12 +3,7 @@ package com.stileeducation.markr.controller; import com.stileeducation.markr.dto.AggregateResponseDTO; import com.stileeducation.markr.dto.ImportResponseDTO; import com.stileeducation.markr.dto.MCQTestResultsDTO; -import com.stileeducation.markr.repository.TestRepository; -import com.stileeducation.markr.repository.TestResultRepository; -import com.stileeducation.markr.service.StudentService; import com.stileeducation.markr.service.TestResultsService; -import com.stileeducation.markr.service.TestService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; @@ -23,29 +18,13 @@ 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; + private final TestResultsService testResultsService; public TestResultsController(TestResultsService testResultsService) { this.testResultsService = testResultsService; } - @PostMapping( - value = IMPORT_ENDPOINT, - consumes = "text/xml+markr", - produces = "application/json") + @PostMapping(value = IMPORT_ENDPOINT, consumes = "text/xml+markr", produces = "application/json") public ResponseEntity<ImportResponseDTO> postTestResults(@Validated @RequestBody MCQTestResultsDTO testResults) { ImportResponseDTO response = testResultsService.processTestResults(testResults); if ("failure".equals(response.getStatus())) { @@ -54,9 +33,7 @@ public class TestResultsController { return new ResponseEntity<>(response, HttpStatus.OK); } - @GetMapping( - value = AGGREGATE_ENDPOINT, - produces = "application/json") + @GetMapping(value = AGGREGATE_ENDPOINT, produces = "application/json") public AggregateResponseDTO getAggregatedResults(@PathVariable("test-id") String testId) { return testResultsService.aggregateTestResults(testId); } diff --git a/src/main/java/com/stileeducation/markr/service/StudentService.java b/src/main/java/com/stileeducation/markr/service/StudentService.java index 3ce28c0..95ce182 100644 --- a/src/main/java/com/stileeducation/markr/service/StudentService.java +++ b/src/main/java/com/stileeducation/markr/service/StudentService.java @@ -2,7 +2,6 @@ package com.stileeducation.markr.service; import com.stileeducation.markr.entity.Student; import com.stileeducation.markr.repository.StudentRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Optional; @@ -10,8 +9,11 @@ import java.util.Optional; @Service public class StudentService { - @Autowired - private StudentRepository studentRepository; + private final StudentRepository studentRepository; + + public StudentService(StudentRepository studentRepository) { + this.studentRepository = studentRepository; + } public Student findOrCreateStudent(String firstName, String lastName, String studentNumber) { Optional<Student> optionalStudent = studentRepository.findByStudentNumber(studentNumber); diff --git a/src/main/java/com/stileeducation/markr/service/TestResultsService.java b/src/main/java/com/stileeducation/markr/service/TestResultsService.java index 51efe95..0c0fa66 100644 --- a/src/main/java/com/stileeducation/markr/service/TestResultsService.java +++ b/src/main/java/com/stileeducation/markr/service/TestResultsService.java @@ -10,7 +10,6 @@ import com.stileeducation.markr.entity.TestResult; import com.stileeducation.markr.repository.TestResultRepository; import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; import org.apache.commons.math3.stat.descriptive.rank.Percentile; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @@ -21,14 +20,17 @@ public class TestResultsService { public static final boolean IS_BIAS_CORRECTED = false; - @Autowired - private TestResultRepository testResultRepository; + private final TestResultRepository testResultRepository; - @Autowired - private StudentService studentService; + private final StudentService studentService; - @Autowired - private TestService testService; + private final TestService testService; + + public TestResultsService(TestResultRepository testResultRepository, StudentService studentService, TestService testService) { + this.testResultRepository = testResultRepository; + this.studentService = studentService; + this.testService = testService; + } public TestResult findOrCreateTestResult(Student student, Test test, Integer marksAwarded) { Optional<TestResult> optionalTestResult = testResultRepository.findByStudentAndTest(student, test); diff --git a/src/main/java/com/stileeducation/markr/service/TestService.java b/src/main/java/com/stileeducation/markr/service/TestService.java index f3231b9..0478c3a 100644 --- a/src/main/java/com/stileeducation/markr/service/TestService.java +++ b/src/main/java/com/stileeducation/markr/service/TestService.java @@ -2,7 +2,6 @@ package com.stileeducation.markr.service; import com.stileeducation.markr.entity.Test; import com.stileeducation.markr.repository.TestRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Optional; @@ -10,9 +9,13 @@ import java.util.Optional; @Service public class TestService { - @Autowired + final TestRepository testRepository; + public TestService(TestRepository testRepository) { + this.testRepository = testRepository; + } + public Test findOrCreateTest(String testId, Integer marksAvailable) { Optional<Test> optionalTest = testRepository.findByTestId(testId); if (optionalTest.isPresent()) { |
