1 | package project.educatum.service.impl;
|
---|
2 |
|
---|
3 | import org.springframework.stereotype.Service;
|
---|
4 | import project.educatum.model.Admin;
|
---|
5 | import project.educatum.model.Qualification;
|
---|
6 | import project.educatum.model.Teacher;
|
---|
7 | import project.educatum.model.exceptions.AdminNotFoundException;
|
---|
8 | import project.educatum.model.exceptions.TeacherNotFoundException;
|
---|
9 | import project.educatum.repository.AdminRepository;
|
---|
10 | import project.educatum.repository.QualificationRepository;
|
---|
11 | import project.educatum.repository.TeacherRepository;
|
---|
12 | import project.educatum.service.QualificationService;
|
---|
13 |
|
---|
14 | @Service
|
---|
15 | public class QualificationServiceImpl implements QualificationService {
|
---|
16 |
|
---|
17 | private final QualificationRepository qualificationRepository;
|
---|
18 | private final TeacherRepository teacherRepository;
|
---|
19 | private final AdminRepository adminRepository;
|
---|
20 |
|
---|
21 | public QualificationServiceImpl(QualificationRepository qualificationRepository, TeacherRepository teacherRepository, AdminRepository adminRepository) {
|
---|
22 | this.qualificationRepository = qualificationRepository;
|
---|
23 | this.teacherRepository = teacherRepository;
|
---|
24 | this.adminRepository = adminRepository;
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public void insert(String document, Integer teacherID) {
|
---|
29 | Teacher n = teacherRepository.findById(teacherID).orElseThrow(TeacherNotFoundException::new);
|
---|
30 | Admin a = adminRepository.findById(1).orElseThrow(AdminNotFoundException::new);
|
---|
31 | Qualification qualification = new Qualification();
|
---|
32 | qualification.setDocument(document);
|
---|
33 | qualification.setIdAdmin(a);
|
---|
34 | qualification.setIdTeacher(n);
|
---|
35 | qualificationRepository.save(qualification);
|
---|
36 | }
|
---|
37 |
|
---|
38 | }
|
---|