Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Clean up DAOs
Browse files Browse the repository at this point in the history
  • Loading branch information
msathieu committed Mar 5, 2024
1 parent 422c17b commit 4319bce
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 67 deletions.
11 changes: 4 additions & 7 deletions backend/db/interface/AdminDAO.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
19 changes: 8 additions & 11 deletions backend/db/interface/GroupDAO.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down
13 changes: 5 additions & 8 deletions backend/db/interface/ProjectDAO.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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.
Expand All @@ -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.
Expand Down
11 changes: 4 additions & 7 deletions backend/db/interface/StudentDAO.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
15 changes: 6 additions & 9 deletions backend/db/interface/SubjectDAO.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
17 changes: 7 additions & 10 deletions backend/db/interface/SubmissionDAO.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
11 changes: 4 additions & 7 deletions backend/db/interface/TeacherDAO.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 3 additions & 7 deletions backend/db/interface/UserDAO.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion backend/routes/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 4319bce

Please sign in to comment.