source: src/main/java/service/impl/StudentSubjectServiceImpl.java@ 1eb7a55

Last change on this file since 1eb7a55 was 1eb7a55, checked in by Elena Markovska <elena.elenamarkovska@…>, 11 days ago

Initial commit - Scholaris project code

  • Property mode set to 100644
File size: 1.2 KB
Line 
1package service.impl;
2
3import DAO.impl.StudentSubjectDAOImpl;
4import model.StudentSubject;
5import java.sql.SQLException;
6import java.util.List;
7
8public class StudentSubjectServiceImpl {
9 private final StudentSubjectDAOImpl dao = new StudentSubjectDAOImpl();
10
11 public void enrollStudent(StudentSubject ss) throws SQLException {
12 // Business Logic: New enrollments should always start with 0 absences
13 ss.setAbsences_count(0);
14 dao.save(ss);
15 }
16
17 public List<StudentSubject> getAllEnrollments() throws SQLException {
18 return dao.getAll();
19 }
20
21 public void updateResult(StudentSubject ss) throws SQLException {
22 // Business Validation: Ensure grade is valid before calling DB
23 if (ss.getFinal_grade() != null) {
24 if (ss.getFinal_grade() < 5 || ss.getFinal_grade() > 10) {
25 throw new IllegalArgumentException("Grade must be between 5 and 10.");
26 }
27 }
28 dao.update(ss);
29 }
30
31 public void removeEnrollment(Long ss_id) throws SQLException {
32 dao.delete(ss_id);
33 }
34
35 public StudentSubject getEnrollment(Long ss_id) throws SQLException {
36 return dao.getById(ss_id);
37 }
38}
Note: See TracBrowser for help on using the repository browser.