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

Commit

Permalink
Remove id lists
Browse files Browse the repository at this point in the history
  • Loading branch information
msathieu committed Feb 25, 2024
1 parent e04e557 commit f84d7de
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 31 deletions.
25 changes: 4 additions & 21 deletions backend/db/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Teacher(db.Model):
subjects: Mapped[list["Subject"]] = relationship(secondary=teachers_subjects, back_populates="teachers")

def to_domain_model(self) -> TeacherDataclass:
return TeacherDataclass(id=self.id, subject_ids=[subject.id for subject in self.subjects])
return TeacherDataclass(id=self.id)


class Student(db.Model):
Expand All @@ -65,12 +65,7 @@ class Student(db.Model):
submissions: Mapped[list["Submission"]] = relationship(back_populates="student")

def to_domain_model(self) -> StudentDataclass:
return StudentDataclass(
id=self.id,
subject_ids=[i.id for i in self.subjects],
group_ids=[i.id for i in self.groups],
submission_ids=[i.id for i in self.submissions],
)
return StudentDataclass(id=self.id)


class Subject(db.Model):
Expand All @@ -81,13 +76,7 @@ class Subject(db.Model):
projects: Mapped[list["Project"]] = relationship(back_populates="subject")

def to_domain_model(self) -> SubjectDataclass:
return SubjectDataclass(
id=self.id,
name=self.name,
teacher_ids=[i.id for i in self.teachers],
student_ids=[i.id for i in self.students],
project_ids=[i.id for i in self.projects],
)
return SubjectDataclass(id=self.id, name=self.name)


class Project(db.Model):
Expand All @@ -112,7 +101,6 @@ def to_domain_model(self) -> ProjectDataclass:
visible=self.visible,
max_students=self.max_students,
subject_id=self.subject_id,
group_ids=[i.id for i in self.groups],
)


Expand All @@ -124,12 +112,7 @@ class Group(db.Model):
submissions: Mapped[list["Submission"]] = relationship(back_populates="group")

def to_domain_model(self) -> GroupDataclass:
return GroupDataclass(
id=self.id,
project_id=self.project_id,
student_ids=[i.id for i in self.students],
submission_ids=[i.id for i in self.submissions],
)
return GroupDataclass(id=self.id, project_id=self.project_id)


class Submission(db.Model):
Expand Down
2 changes: 0 additions & 2 deletions backend/domain/models/GroupDataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@
class GroupDataclass(JsonRepresentable):
project_id: int
id: int | None = None
student_ids: list[int] | None = None
submission_ids: list[int] | None = None
1 change: 0 additions & 1 deletion backend/domain/models/ProjectDataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ class ProjectDataclass(JsonRepresentable):
max_students: int
subject_id: int
id: int | None = None
group_ids: list[int] | None = None
3 changes: 0 additions & 3 deletions backend/domain/models/StudentDataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@
@dataclass()
class StudentDataclass(JsonRepresentable):
id: int
subject_ids: list[int] | None = None
group_ids: list[int] | None = None
submission_ids: list[int] | None = None
3 changes: 0 additions & 3 deletions backend/domain/models/SubjectDataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@
class SubjectDataclass(JsonRepresentable):
name: str
id: int | None = None
teacher_ids: list[int] | None = None
student_ids: list[int] | None = None
project_ids: list[int] | None = None
1 change: 0 additions & 1 deletion backend/domain/models/TeacherDataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
@dataclass()
class TeacherDataclass(JsonRepresentable):
id: int
subject_ids: list[int] | None = None

0 comments on commit f84d7de

Please sign in to comment.