diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-07-23 23:23:45 +1000 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-07-23 23:23:45 +1000 |
| commit | f08b2fa7e6a977a18d6b9f14fb73c18ec73ec5df (patch) | |
| tree | 48ce214bc609130748b9630c2017000cafd29c2b /src/main/java/com/stileeducation/markr/service/StudentService.java | |
| parent | fa34f76ad8ebccb96012b45a4207532846cfa03f (diff) | |
Implement domain services
Implement core business logic for working with Student, Test, and TestResult.
Diffstat (limited to 'src/main/java/com/stileeducation/markr/service/StudentService.java')
| -rw-r--r-- | src/main/java/com/stileeducation/markr/service/StudentService.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main/java/com/stileeducation/markr/service/StudentService.java b/src/main/java/com/stileeducation/markr/service/StudentService.java new file mode 100644 index 0000000..4af4d63 --- /dev/null +++ b/src/main/java/com/stileeducation/markr/service/StudentService.java @@ -0,0 +1,28 @@ +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; + +@Service +public class StudentService { + + @Autowired + private StudentRepository studentRepository; + + public Student findOrCreateStudent(String firstName, String lastName, String studentNumber) { + Optional<Student> optionalStudent = studentRepository.findByStudentNumber(studentNumber); + if (optionalStudent.isPresent()) { + return optionalStudent.get(); + } else { + Student student = new Student(); + student.setFirstName(firstName); + student.setLastName(lastName); + student.setStudentNumber(studentNumber); + return studentRepository.save(student); + } + } +} |
