-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentService.java
More file actions
31 lines (25 loc) · 927 Bytes
/
StudentService.java
File metadata and controls
31 lines (25 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.example.apiapplicationNEW.student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.Month;
import java.util.List;
import java.util.Optional;
@Service
public class StudentService{
private final StudentRepository studentRepository;
@Autowired
public StudentService(StudentRepository studentRepository) {
this.studentRepository = studentRepository;
}
public void addNewStudent(Student student) {
Optional<Student> studentOptional = studentRepository.findStudentByEmail(student.getEmail());
if(studentOptional.isPresent()){
throw new IllegalStateException("email taken");
}
studentRepository.save(student);
}
public List<Student> getStudent(){
return studentRepository.findAll();
}
}