summaryrefslogtreecommitdiff
path: root/src/main/java/com/stileeducation/markr/service/TestService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/stileeducation/markr/service/TestService.java')
-rw-r--r--src/main/java/com/stileeducation/markr/service/TestService.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main/java/com/stileeducation/markr/service/TestService.java b/src/main/java/com/stileeducation/markr/service/TestService.java
new file mode 100644
index 0000000..f3ba98c
--- /dev/null
+++ b/src/main/java/com/stileeducation/markr/service/TestService.java
@@ -0,0 +1,28 @@
+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;
+
+@Service
+public class TestService {
+
+ @Autowired
+ TestRepository testRepository;
+
+ public Test findOrCreateTest(String testId, Integer marksAvailable) {
+ Optional<Test> optionalTest = testRepository.findByTestId(testId);
+ if (optionalTest.isPresent()) {
+ return optionalTest.get();
+ } else {
+ Test test = new Test();
+ test.setTestId(testId);
+ test.setMarksAvailable(marksAvailable);
+ return testRepository.save(test);
+ }
+ }
+
+}