clean: clean python code
This commit is contained in:
		
							
								
								
									
										50
									
								
								repositories/student_repository.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								repositories/student_repository.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | ||||
| from typing import List, Optional | ||||
| from sqlalchemy.orm import joinedload | ||||
| from models import Student, ClassGroup | ||||
| from .base_repository import BaseRepository | ||||
|  | ||||
|  | ||||
| class StudentRepository(BaseRepository[Student]): | ||||
|     """Repository pour les étudiants.""" | ||||
|      | ||||
|     def __init__(self): | ||||
|         super().__init__(Student) | ||||
|      | ||||
|     def find_by_class_ordered(self, class_group_id: int) -> List[Student]: | ||||
|         """Trouve les étudiants d'une classe triés par nom.""" | ||||
|         return Student.query.filter_by( | ||||
|             class_group_id=class_group_id | ||||
|         ).order_by( | ||||
|             Student.last_name,  | ||||
|             Student.first_name | ||||
|         ).all() | ||||
|      | ||||
|     def find_all_with_class_ordered(self) -> List[Student]: | ||||
|         """Trouve tous les étudiants avec leur classe, triés par classe puis nom.""" | ||||
|         return Student.query.options( | ||||
|             joinedload(Student.class_group) | ||||
|         ).join( | ||||
|             ClassGroup | ||||
|         ).order_by( | ||||
|             ClassGroup.name, | ||||
|             Student.last_name,  | ||||
|             Student.first_name | ||||
|         ).all() | ||||
|      | ||||
|     def find_by_class_group(self, class_group_id: int) -> List[Student]: | ||||
|         """Trouve tous les étudiants d'une classe.""" | ||||
|         return Student.query.filter_by( | ||||
|             class_group_id=class_group_id | ||||
|         ).all() | ||||
|      | ||||
|     def count_by_class_group(self, class_group_id: int) -> int: | ||||
|         """Compte les étudiants d'une classe.""" | ||||
|         return Student.query.filter_by( | ||||
|             class_group_id=class_group_id | ||||
|         ).count() | ||||
|      | ||||
|     def find_with_class_group(self, id: int) -> Optional[Student]: | ||||
|         """Trouve un étudiant avec sa classe.""" | ||||
|         return Student.query.options( | ||||
|             joinedload(Student.class_group) | ||||
|         ).filter_by(id=id).first() | ||||
		Reference in New Issue
	
	Block a user