diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-07-26 15:16:26 +1000 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-07-26 15:16:26 +1000 |
| commit | e11138e2b39e07537d836d9a51e3926a78c8b870 (patch) | |
| tree | 215e27a9206bc10fbeb5db4b73f8e92acc4fbf84 /src/main/java/com/stileeducation/markr/service/TestService.java | |
| parent | 3ac208066db6d11e1a8cc1f6174c6d86b5ac603b (diff) | |
| parent | b59d2f0c722d2e21194ed8d66a17be8128ba7b39 (diff) | |
Merge branch 'caching-issue'
Diffstat (limited to 'src/main/java/com/stileeducation/markr/service/TestService.java')
| -rw-r--r-- | src/main/java/com/stileeducation/markr/service/TestService.java | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/main/java/com/stileeducation/markr/service/TestService.java b/src/main/java/com/stileeducation/markr/service/TestService.java index 0e109ac..f42da1a 100644 --- a/src/main/java/com/stileeducation/markr/service/TestService.java +++ b/src/main/java/com/stileeducation/markr/service/TestService.java @@ -2,6 +2,7 @@ package com.stileeducation.markr.service; import com.stileeducation.markr.entity.Test; import com.stileeducation.markr.repository.TestRepository; +import jakarta.transaction.Transactional; import org.springframework.stereotype.Service; import java.util.Optional; @@ -16,22 +17,27 @@ public class TestService { this.testRepository = testRepository; } + @Transactional public Optional<Test> findTest(String testId) { return testRepository.findByTestId(testId); } + @Transactional public Test findOrCreateTest(String testId, Integer marksAvailable) { Optional<Test> optionalTest = testRepository.findByTestId(testId); + if (optionalTest.isPresent()) { Test test = optionalTest.get(); - if (test.getMarksAvailable() < marksAvailable) { + if (marksAvailable > test.getMarksAvailable()) { test.setMarksAvailable(marksAvailable); + test.setCreated(false); test.setUpdated(true); - testRepository.save(test); + return testRepository.save(test); } else { + test.setCreated(false); test.setUpdated(false); + return test; } - return test; } else { Test test = new Test(); test.setTestId(testId); |
