diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-07-26 15:07:54 +1000 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-07-26 15:07:54 +1000 |
| commit | 7d4d645eb24a30888825f6cdf50cb3eec6ef59f7 (patch) | |
| tree | 74ea58ed48b57f44e27e3e52fea7ee1c5f0e8b7c /src/main/java/com/stileeducation/markr/service/StudentService.java | |
| parent | 39e7e3344bf0827fe9563dc1f08d18084316fd6f (diff) | |
Add test cases for multiple submissions
Add test cases which exercise the logic for updating the marks available
and marks obtained.
Update the service method so that they are transactional and reset the
transient 'updated' and 'created' flags after reloading entites to
ensure accurate update/create reporting.
Diffstat (limited to 'src/main/java/com/stileeducation/markr/service/StudentService.java')
| -rw-r--r-- | src/main/java/com/stileeducation/markr/service/StudentService.java | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/main/java/com/stileeducation/markr/service/StudentService.java b/src/main/java/com/stileeducation/markr/service/StudentService.java index 95ce182..e49f06a 100644 --- a/src/main/java/com/stileeducation/markr/service/StudentService.java +++ b/src/main/java/com/stileeducation/markr/service/StudentService.java @@ -2,6 +2,7 @@ package com.stileeducation.markr.service; import com.stileeducation.markr.entity.Student; import com.stileeducation.markr.repository.StudentRepository; +import jakarta.transaction.Transactional; import org.springframework.stereotype.Service; import java.util.Optional; @@ -15,10 +16,15 @@ public class StudentService { this.studentRepository = studentRepository; } + @Transactional public Student findOrCreateStudent(String firstName, String lastName, String studentNumber) { Optional<Student> optionalStudent = studentRepository.findByStudentNumber(studentNumber); if (optionalStudent.isPresent()) { - return optionalStudent.get(); + Student student = optionalStudent.get(); + // Reset transients + student.setCreated(false); + student.setUpdated(false); + return student; } else { Student student = new Student(); student.setFirstName(firstName); |
