|
| 1 | +# BLL/students.py |
| 2 | +from DAL.studentDAL import StudentDAL |
| 3 | +from DAL.teacherDAL import TeacherDAL |
| 4 | +from DAL.classesDAL import ClassesDAL |
| 5 | + |
| 6 | +# Student Class |
| 7 | +class Student: |
| 8 | + """ |
| 9 | + The Student class represents a student entity and provides methods to interact with the student data. |
| 10 | + Attributes: |
| 11 | + id (int, optional): The unique identifier for the student. |
| 12 | + first_name (str, optional): The first name of the student. |
| 13 | + last_name (str, optional): The last name of the student. |
| 14 | + email (str, optional): The email address of the student. |
| 15 | + date_of_birth (str, optional): The date of birth of the student. |
| 16 | + grade (str, optional): The grade of the student. |
| 17 | + Methods: |
| 18 | + add(): |
| 19 | + Adds a new student record using a stored procedure. |
| 20 | + read(): |
| 21 | + Reads the student record based on the student's ID. |
| 22 | + getStudents(): |
| 23 | + Retrieves all student records. |
| 24 | + getStudentsWithClasses(): |
| 25 | + Retrieves all student records along with their associated classes. |
| 26 | + """ |
| 27 | + def __init__(self, id=None, first_name=None, last_name=None, email=None, date_of_birth=None, grade=None): |
| 28 | + """ |
| 29 | + Initializes a new instance of the Student class. |
| 30 | +
|
| 31 | + Args: |
| 32 | + id (int, optional): The unique identifier for the student. Defaults to None. |
| 33 | + first_name (str, optional): The first name of the student. Defaults to None. |
| 34 | + last_name (str, optional): The last name of the student. Defaults to None. |
| 35 | + email (str, optional): The email address of the student. Defaults to None. |
| 36 | + date_of_birth (str, optional): The date of birth of the student. Defaults to None. |
| 37 | + grade (str, optional): The grade of the student. Defaults to None. |
| 38 | + """ |
| 39 | + self.studentDal = StudentDAL() |
| 40 | + self.id = id |
| 41 | + self.first_name = first_name |
| 42 | + self.last_name = last_name |
| 43 | + self.email = email |
| 44 | + self.date_of_birth = date_of_birth |
| 45 | + self.grade = grade |
| 46 | + |
| 47 | + def add(self): |
| 48 | + """ |
| 49 | + Adds a new student record to the database using a stored procedure. |
| 50 | +
|
| 51 | + This method calls the `add_using_procedure` method of the `studentDal` object, |
| 52 | + passing the student's first name, last name, email, date of birth, and grade |
| 53 | + as parameters. |
| 54 | +
|
| 55 | + Parameters: |
| 56 | + None |
| 57 | +
|
| 58 | + Returns: |
| 59 | + None |
| 60 | + """ |
| 61 | + self.studentDal.add_using_procedure( |
| 62 | + self.first_name, |
| 63 | + self.last_name, |
| 64 | + self.email, |
| 65 | + self.date_of_birth, |
| 66 | + self.grade |
| 67 | + ) |
| 68 | + |
| 69 | + def read(self): |
| 70 | + """ |
| 71 | + Reads the student data from the data access layer (DAL) using the student's ID. |
| 72 | +
|
| 73 | + Returns: |
| 74 | + dict: A dictionary containing the student's data. |
| 75 | + """ |
| 76 | + return self.studentDal.read(self.id) |
| 77 | + |
| 78 | + def getStudents(self): |
| 79 | + """ |
| 80 | + Retrieves a list of all students from the data access layer. |
| 81 | +
|
| 82 | + Returns: |
| 83 | + list: A list of student records. |
| 84 | + """ |
| 85 | + return self.studentDal.read_all() |
| 86 | + |
| 87 | + def getStudentsWithClasses(self): |
| 88 | + """ |
| 89 | + Retrieves a list of students along with their associated classes. |
| 90 | +
|
| 91 | + Returns: |
| 92 | + list: A list of dictionaries, where each dictionary contains student information |
| 93 | + and their associated classes. |
| 94 | + """ |
| 95 | + return self.studentDal.read_all_with_classes() |
| 96 | + |
| 97 | +class Teacher: |
| 98 | + """ |
| 99 | + A class to represent a teacher. |
| 100 | +
|
| 101 | + Attributes: |
| 102 | + ---------- |
| 103 | + id : int, optional |
| 104 | + The unique identifier for the teacher (default is None). |
| 105 | + first_name : str, optional |
| 106 | + The first name of the teacher (default is None). |
| 107 | + last_name : str, optional |
| 108 | + The last name of the teacher (default is None). |
| 109 | + email : str, optional |
| 110 | + The email address of the teacher (default is None). |
| 111 | + teacherDal : TeacherDAL |
| 112 | + An instance of the TeacherDAL class for database operations. |
| 113 | +
|
| 114 | + Methods: |
| 115 | + ------- |
| 116 | + add(): |
| 117 | + Adds the teacher's information to the database. |
| 118 | + read(): |
| 119 | + Reads the teacher's information from the database using the teacher's id. |
| 120 | + """ |
| 121 | + |
| 122 | + def __init__(self, id=None, first_name=None, last_name=None, email=None): |
| 123 | + """ |
| 124 | + Constructs all the necessary attributes for the teacher object. |
| 125 | +
|
| 126 | + Parameters: |
| 127 | + ---------- |
| 128 | + id : int, optional |
| 129 | + The unique identifier for the teacher (default is None). |
| 130 | + first_name : str, optional |
| 131 | + The first name of the teacher (default is None). |
| 132 | + last_name : str, optional |
| 133 | + The last name of the teacher (default is None). |
| 134 | + email : str, optional |
| 135 | + The email address of the teacher (default is None). |
| 136 | + """ |
| 137 | + self.teacherDal = TeacherDAL() |
| 138 | + self.id = id |
| 139 | + self.first_name = first_name |
| 140 | + self.last_name = last_name |
| 141 | + self.email = email |
| 142 | + |
| 143 | + def add(self): |
| 144 | + """ |
| 145 | + Adds the teacher's information to the database. |
| 146 | +
|
| 147 | + This method uses the TeacherDAL instance to add the teacher's |
| 148 | + first name, last name, and email to the database. |
| 149 | + """ |
| 150 | + self.teacherDal.add( |
| 151 | + self.first_name, |
| 152 | + self.last_name, |
| 153 | + self.email |
| 154 | + ) |
| 155 | + |
| 156 | + def read(self): |
| 157 | + """ |
| 158 | + Reads the teacher's information from the database using the teacher's id. |
| 159 | +
|
| 160 | + Returns: |
| 161 | + ------- |
| 162 | + dict |
| 163 | + A dictionary containing the teacher's information retrieved from the database. |
| 164 | + """ |
| 165 | + return self.teacherDal.read(self.id) |
| 166 | + |
| 167 | +class Class: |
| 168 | + """ |
| 169 | + A class to represent a school class. |
| 170 | +
|
| 171 | + Attributes: |
| 172 | + ---------- |
| 173 | + id : int, optional |
| 174 | + The unique identifier for the class (default is None). |
| 175 | + room_number : str, optional |
| 176 | + The room number where the class is held (default is None). |
| 177 | + subject : str, optional |
| 178 | + The subject taught in the class (default is None). |
| 179 | + class_grade : str, optional |
| 180 | + The grade level of the class (default is None). |
| 181 | + teacher_id : int, optional |
| 182 | + The unique identifier for the teacher of the class (default is None). |
| 183 | + student_id : int, optional |
| 184 | + The unique identifier for the student in the class (default is None). |
| 185 | + classDal : ClassesDAL |
| 186 | + An instance of the ClassesDAL class for database operations. |
| 187 | +
|
| 188 | + Methods: |
| 189 | + ------- |
| 190 | + add(): |
| 191 | + Adds the class information to the database. |
| 192 | + read(): |
| 193 | + Reads the class information from the database using the class id. |
| 194 | + """ |
| 195 | + |
| 196 | + def __init__(self, id=None, room_number=None, subject=None, class_grade=None, teacher_id=None, student_id=None): |
| 197 | + """ |
| 198 | + Constructs all the necessary attributes for the class object. |
| 199 | +
|
| 200 | + Parameters: |
| 201 | + ---------- |
| 202 | + id : int, optional |
| 203 | + The unique identifier for the class (default is None). |
| 204 | + room_number : str, optional |
| 205 | + The room number where the class is held (default is None). |
| 206 | + subject : str, optional |
| 207 | + The subject taught in the class (default is None). |
| 208 | + class_grade : str, optional |
| 209 | + The grade level of the class (default is None). |
| 210 | + teacher_id : int, optional |
| 211 | + The unique identifier for the teacher of the class (default is None). |
| 212 | + student_id : int, optional |
| 213 | + The unique identifier for the student in the class (default is None). |
| 214 | + """ |
| 215 | + self.classDal = ClassesDAL() |
| 216 | + self.id = id |
| 217 | + self.room_number = room_number |
| 218 | + self.subject = subject |
| 219 | + self.class_grade = class_grade |
| 220 | + self.teacher_id = teacher_id |
| 221 | + self.student_id = student_id |
| 222 | + |
| 223 | + def add(self): |
| 224 | + """ |
| 225 | + Adds the class information to the database. |
| 226 | +
|
| 227 | + This method uses the ClassesDAL instance to add the class's |
| 228 | + room number, subject, class grade, teacher id, and student id to the database. |
| 229 | + """ |
| 230 | + self.classDal.add( |
| 231 | + self.room_number, |
| 232 | + self.subject, |
| 233 | + self.class_grade, |
| 234 | + self.teacher_id, |
| 235 | + self.student_id |
| 236 | + ) |
| 237 | + |
| 238 | + def read(self): |
| 239 | + """ |
| 240 | + Reads the class information from the database using the class id. |
| 241 | +
|
| 242 | + Returns: |
| 243 | + ------- |
| 244 | + dict |
| 245 | + A dictionary containing the class information retrieved from the database. |
| 246 | + """ |
| 247 | + return self.classDal.read(self.id) |
0 commit comments