From 4319bce4bc44b4cab8fb304b5d66b4877b8bb5a5 Mon Sep 17 00:00:00 2001 From: Mathieu Strypsteen Date: Tue, 5 Mar 2024 13:19:48 +0100 Subject: [PATCH] Clean up DAOs --- backend/db/interface/AdminDAO.py | 11 ++++------- backend/db/interface/GroupDAO.py | 19 ++++++++----------- backend/db/interface/ProjectDAO.py | 13 +++++-------- backend/db/interface/StudentDAO.py | 11 ++++------- backend/db/interface/SubjectDAO.py | 15 ++++++--------- backend/db/interface/SubmissionDAO.py | 17 +++++++---------- backend/db/interface/TeacherDAO.py | 11 ++++------- backend/db/interface/UserDAO.py | 10 +++------- backend/routes/projects.py | 2 +- 9 files changed, 42 insertions(+), 67 deletions(-) diff --git a/backend/db/interface/AdminDAO.py b/backend/db/interface/AdminDAO.py index c5a649d5..7b78c652 100644 --- a/backend/db/interface/AdminDAO.py +++ b/backend/db/interface/AdminDAO.py @@ -1,16 +1,13 @@ from abc import abstractmethod -from typing import TYPE_CHECKING from db.interface.AbstractDAO import AbstractDAO +from db.models.models import Admin +from domain.models.AdminDataclass import AdminDataclass -if TYPE_CHECKING: - from db.models.models import Admin # noqa: F401 - from domain.models.AdminDataclass import AdminDataclass - -class AdminDAO(AbstractDAO["Admin", "AdminDataclass"]): +class AdminDAO(AbstractDAO[Admin, AdminDataclass]): @abstractmethod - def create_admin(self, name: str, email: str) -> "AdminDataclass": + def create_admin(self, name: str, email: str) -> AdminDataclass: """ Maakt een nieuwe admin aan. diff --git a/backend/db/interface/GroupDAO.py b/backend/db/interface/GroupDAO.py index 1a962073..b1b9e9d3 100644 --- a/backend/db/interface/GroupDAO.py +++ b/backend/db/interface/GroupDAO.py @@ -1,17 +1,14 @@ from abc import abstractmethod -from typing import TYPE_CHECKING from db.interface.AbstractDAO import AbstractDAO +from db.models.models import Group +from domain.models.GroupDataclass import GroupDataclass +from domain.models.StudentDataclass import StudentDataclass -if TYPE_CHECKING: - from db.models.models import Group # noqa: F401 - from domain.models.GroupDataclass import GroupDataclass - from domain.models.StudentDataclass import StudentDataclass - -class GroupDAO(AbstractDAO["Group", "GroupDataclass"]): +class GroupDAO(AbstractDAO[Group, GroupDataclass]): @abstractmethod - def create_group(self, project_id: int) -> "GroupDataclass": + def create_group(self, project_id: int) -> GroupDataclass: """ Creëert een nieuw GroupDataClass in de database en associeert het met een ProjectDataClass. @@ -22,7 +19,7 @@ def create_group(self, project_id: int) -> "GroupDataclass": raise NotImplementedError @abstractmethod - def get_groups_of_project(self, project_id: int) -> list["GroupDataclass"]: + def get_groups_of_project(self, project_id: int) -> list[GroupDataclass]: """ Haalt alle groepen op die bij een bepaald project horen. @@ -32,7 +29,7 @@ def get_groups_of_project(self, project_id: int) -> list["GroupDataclass"]: raise NotImplementedError @abstractmethod - def get_groups_of_student(self, student_id: int) -> list["GroupDataclass"]: + def get_groups_of_student(self, student_id: int) -> list[GroupDataclass]: """ Haalt alle groepen op die bij een bepaalde student horen. @@ -53,7 +50,7 @@ def add_student_to_group(self, student_id: int, group_id: int) -> None: raise NotImplementedError @abstractmethod - def get_students_of_group(self, group_id: int) -> list["StudentDataclass"]: + def get_students_of_group(self, group_id: int) -> list[StudentDataclass]: """ Gaat alle studenten geven die in een bepaalde groep zitten diff --git a/backend/db/interface/ProjectDAO.py b/backend/db/interface/ProjectDAO.py index c5f46b1e..ed2d1e6a 100644 --- a/backend/db/interface/ProjectDAO.py +++ b/backend/db/interface/ProjectDAO.py @@ -1,15 +1,12 @@ from abc import abstractmethod from datetime import datetime -from typing import TYPE_CHECKING from db.interface.AbstractDAO import AbstractDAO +from db.models.models import Project +from domain.models.ProjectDataclass import ProjectDataclass -if TYPE_CHECKING: - from db.models.models import Project # noqa: F401 - from domain.models.ProjectDataclass import ProjectDataclass - -class ProjectDAO(AbstractDAO["Project", "ProjectDataclass"]): +class ProjectDAO(AbstractDAO[Project, ProjectDataclass]): @abstractmethod def create_project( self, @@ -21,7 +18,7 @@ def create_project( requirements: str, visible: bool, max_students: int, - ) -> "ProjectDataclass": + ) -> ProjectDataclass: """ Creëert een nieuw ProjectDataClass in de database en associeert het met een SubjectDataClass. @@ -39,7 +36,7 @@ def create_project( raise NotImplementedError @abstractmethod - def get_projects_of_subject(self, subject_id: int) -> list["ProjectDataclass"]: + def get_projects_of_subject(self, subject_id: int) -> list[ProjectDataclass]: """ Haalt alle projecten op die bij een bepaald subject horen. diff --git a/backend/db/interface/StudentDAO.py b/backend/db/interface/StudentDAO.py index a0075422..e7f9e8da 100644 --- a/backend/db/interface/StudentDAO.py +++ b/backend/db/interface/StudentDAO.py @@ -1,16 +1,13 @@ from abc import abstractmethod -from typing import TYPE_CHECKING from db.interface.AbstractDAO import AbstractDAO +from db.models.models import Student +from domain.models.StudentDataclass import StudentDataclass -if TYPE_CHECKING: - from db.models.models import Student # noqa: F401 - from domain.models.StudentDataclass import StudentDataclass - -class StudentDAO(AbstractDAO["Student", "StudentDataclass"]): +class StudentDAO(AbstractDAO[Student, StudentDataclass]): @abstractmethod - def create_student(self, name: str, email: str) -> "StudentDataclass": + def create_student(self, name: str, email: str) -> StudentDataclass: """ Maakt een nieuwe student aan. diff --git a/backend/db/interface/SubjectDAO.py b/backend/db/interface/SubjectDAO.py index fd04d162..b759ab12 100644 --- a/backend/db/interface/SubjectDAO.py +++ b/backend/db/interface/SubjectDAO.py @@ -1,16 +1,13 @@ from abc import abstractmethod -from typing import TYPE_CHECKING from db.interface.AbstractDAO import AbstractDAO +from db.models.models import Subject +from domain.models.SubjectDataclass import SubjectDataclass -if TYPE_CHECKING: - from db.models.models import Subject # noqa: F401 - from domain.models.SubjectDataclass import SubjectDataclass - -class SubjectDAO(AbstractDAO["Subject", "SubjectDataclass"]): +class SubjectDAO(AbstractDAO[Subject, SubjectDataclass]): @abstractmethod - def create_subject(self, name: str) -> "SubjectDataclass": + def create_subject(self, name: str) -> SubjectDataclass: """ Creëert een nieuw SubjectDataclass in de database. @@ -20,7 +17,7 @@ def create_subject(self, name: str) -> "SubjectDataclass": raise NotImplementedError @abstractmethod - def get_subjects_of_teacher(self, teacher_id: int) -> list["SubjectDataclass"]: + def get_subjects_of_teacher(self, teacher_id: int) -> list[SubjectDataclass]: """ Haalt de subjects op die door een bepaalde teacher worden gegeven. @@ -30,7 +27,7 @@ def get_subjects_of_teacher(self, teacher_id: int) -> list["SubjectDataclass"]: raise NotImplementedError @abstractmethod - def get_subjects_of_student(self, student_id: int) -> list["SubjectDataclass"]: + def get_subjects_of_student(self, student_id: int) -> list[SubjectDataclass]: """ Haalt de subjects op die door een bepaalde student worden gevolgd. diff --git a/backend/db/interface/SubmissionDAO.py b/backend/db/interface/SubmissionDAO.py index bd9bc873..c5fd33c2 100644 --- a/backend/db/interface/SubmissionDAO.py +++ b/backend/db/interface/SubmissionDAO.py @@ -1,24 +1,21 @@ from abc import abstractmethod from datetime import datetime -from typing import TYPE_CHECKING from db.interface.AbstractDAO import AbstractDAO +from db.models.models import Submission +from domain.models.SubmissionDataclass import SubmissionDataclass, SubmissionState -if TYPE_CHECKING: - from db.models.models import Submission # noqa: F401 - from domain.models.SubmissionDataclass import SubmissionDataclass, SubmissionState - -class SubmissionDAO(AbstractDAO["Submission", "SubmissionDataclass"]): +class SubmissionDAO(AbstractDAO[Submission, SubmissionDataclass]): @abstractmethod def create_submission( self, student_id: int, group_id: int, message: str, - state: "SubmissionState", + state: SubmissionState, date_time: datetime, - ) -> "SubmissionDataclass": + ) -> SubmissionDataclass: """ Creëert een nieuw SubmissionDataClass in de database en associeert het met een StudentDataclass en een GroupDataClass. @@ -32,7 +29,7 @@ def create_submission( raise NotImplementedError @abstractmethod - def get_submissions_of_student(self, student_id: int) -> list["SubmissionDataclass"]: + def get_submissions_of_student(self, student_id: int) -> list[SubmissionDataclass]: """ Haalt alle projecten op die bij een bepaalde student horen. @@ -42,7 +39,7 @@ def get_submissions_of_student(self, student_id: int) -> list["SubmissionDatacla raise NotImplementedError @abstractmethod - def get_submissions_of_group(self, group_id: int) -> list["SubmissionDataclass"]: + def get_submissions_of_group(self, group_id: int) -> list[SubmissionDataclass]: """ Haalt alle projecten op die bij een bepaalde groep horen. diff --git a/backend/db/interface/TeacherDAO.py b/backend/db/interface/TeacherDAO.py index fb33d6a7..99bea93c 100644 --- a/backend/db/interface/TeacherDAO.py +++ b/backend/db/interface/TeacherDAO.py @@ -1,16 +1,13 @@ from abc import abstractmethod -from typing import TYPE_CHECKING from db.interface.AbstractDAO import AbstractDAO +from db.models.models import Teacher +from domain.models.TeacherDataclass import TeacherDataclass -if TYPE_CHECKING: - from db.models.models import Teacher # noqa: F401 - from domain.models.TeacherDataclass import TeacherDataclass - -class TeacherDAO(AbstractDAO["Teacher", "TeacherDataclass"]): +class TeacherDAO(AbstractDAO[Teacher, TeacherDataclass]): @abstractmethod - def create_teacher(self, name: str, email: str) -> "TeacherDataclass": + def create_teacher(self, name: str, email: str) -> TeacherDataclass: """ Maakt een nieuwe teacher aan. diff --git a/backend/db/interface/UserDAO.py b/backend/db/interface/UserDAO.py index 2de84906..6769baba 100644 --- a/backend/db/interface/UserDAO.py +++ b/backend/db/interface/UserDAO.py @@ -1,11 +1,7 @@ -from typing import TYPE_CHECKING - from db.interface.AbstractDAO import AbstractDAO - -if TYPE_CHECKING: - from db.models.models import User # noqa: F401 - from domain.models.UserDataclass import UserDataclass # noqa: F401 +from db.models.models import User +from domain.models.UserDataclass import UserDataclass -class UserDAO(AbstractDAO["User", "UserDataclass"]): +class UserDAO(AbstractDAO[User, UserDataclass]): pass diff --git a/backend/routes/projects.py b/backend/routes/projects.py index 3d0b25dc..88000fe3 100644 --- a/backend/routes/projects.py +++ b/backend/routes/projects.py @@ -27,7 +27,7 @@ def get_subjects(teacher: bool = False) -> list[ProjectDataclass]: return projects -@projects_router.get("/projects/{subject_id}") +@projects_router.get("/projects/{project_id}") def get_project(project_id: int) -> ProjectDataclass: project_dao = get_dao_provider().get_project_dao() subject_dao = get_dao_provider().get_subject_dao()