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

Commit

Permalink
db.session.add verwijderen + toevoegen nieuwe mock data
Browse files Browse the repository at this point in the history
  • Loading branch information
ALBERICLOOS committed Feb 27, 2024
1 parent 4f68cea commit a176995
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
1 change: 0 additions & 1 deletion backend/db/implementation/SqlGroupDAO.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def add_student_to_group(self, student_id: int, group_id: int) -> None:
raise UniqueConstraintError(msg)

group.students.append(student)
db.session.add(group)
db.session.commit()

def get_students_of_group(self, group_id: int) -> list[StudentDataclass]:
Expand Down
2 changes: 0 additions & 2 deletions backend/db/implementation/SqlSubjectDAO.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def add_student_to_subject(self, student_id: int, subject_id: int) -> None:
raise UniqueConstraintError(msg)

student.subjects.append(subject)
db.session.add(student)
db.session.commit()

def add_teacher_to_subject(self, teacher_id: int, subject_id: int) -> None:
Expand All @@ -68,5 +67,4 @@ def add_teacher_to_subject(self, teacher_id: int, subject_id: int) -> None:
raise UniqueConstraintError(msg)

teacher.subjects.append(subject)
db.session.add(teacher)
db.session.commit()
39 changes: 38 additions & 1 deletion backend/fill_database_mock.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
from datetime import datetime

from psycopg2 import tz

from app import app
from db.extensions import db
from db.implementation.SqlAdminDAO import SqlAdminDAO
from db.implementation.SqlGroupDAO import SqlGroupDAO
from db.implementation.SqlProjectDAO import SqlProjectDAO
from db.implementation.SqlStudentDAO import SqlStudentDAO
from db.implementation.SqlSubjectDAO import SqlSubjectDAO
from db.implementation.SqlTeacherDAO import SqlTeacherDAO

if __name__ == "__main__":
with app.app_context():

db.create_all()

admin_dao = SqlAdminDAO()
student_dao = SqlStudentDAO()
teacher_dao = SqlTeacherDAO()
subject_dao = SqlSubjectDAO()
group_dao = SqlGroupDAO()
project_dao = SqlProjectDAO()

# maak een vak
objeprog = subject_dao.create_subject(name="OBJECTGERICHTPROGRAMMEREN")

# maak een project voor dat vak
objeprog_project = project_dao.create_project(subject_id=objeprog.id,
name="PROJECT",
archived=False,
visible=True,
requirements="Maak iets in javafx",
max_students=2,
deadline=datetime(2000, 1, 1, 0, 0, 0, tzinfo=tz.LOCAL))

# maak een groepje voor het project van objeprog
groep1 = group_dao.create_group(project_id=objeprog_project.id)

# maak studenten
student1 = student_dao.create_student("Student1", "[email protected]")
student2 = student_dao.create_student("Student2", "[email protected]")
student3 = student_dao.create_student("Student3", "[email protected]")

# maak teacher
teacher1 = teacher_dao.create_teacher("Teacher1", "[email protected]")

# voeg teacher toe aan objeprog
subject_dao.add_teacher_to_subject(teacher1.id, objeprog.id)

# voeg studenten toe aan de groep
group_dao.add_student_to_group(student1.id, groep1.id)
group_dao.add_student_to_group(student2.id, groep1.id)
group_dao.add_student_to_group(student3.id, groep1.id)

0 comments on commit a176995

Please sign in to comment.