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

Commit

Permalink
toevoegen van SubmissionsDAO
Browse files Browse the repository at this point in the history
  • Loading branch information
ALBERICLOOS committed Feb 25, 2024
1 parent f9ab3d5 commit 8d5e69e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/db/implementation/SqlGroupDAO.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create_group(self, group: GroupDataclass, project_id: int):
raise ItemNotFoundError(f"Het project met id {project_id} kon niet in de databank gevonden worden")
new_group: Group = Group()
new_group.project_id = project_id

new_group.project = project
db.session.add(new_group)
db.session.commit()

Expand Down
48 changes: 48 additions & 0 deletions backend/db/implementation/SqlSubmissionDAO.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from typing import List

from db.errors.database_errors import ItemNotFoundError, UniqueConstraintError
from db.extensions import db
from db.interface.SubmissionDAO import SubmissionDAO
from db.models.models import Student, Subject, Teacher, Project, Group, Submission
from domain.models.models import SubjectDataclass, SubmissionDataclass


class SqlSubmissionDAO(SubmissionDAO):
def create_submission(self, submission: SubmissionDataclass, student_id: int, group_id: int):
student = Student.query.get(student_id)
group = Group.query.get(group_id)
if not student:
raise ItemNotFoundError(f"student met id {student_id} kon niet in de databank gevonden worden")
if not group:
raise ItemNotFoundError(f"group met id {group_id} kon niet in de databank gevonden worden")
new_submission: Submission = Submission()
new_submission.group_id = group_id
new_submission.group = group
new_submission.student_id = student_id
new_submission.student = student
new_submission.date_time = submission.date_time
new_submission.state = submission.state
new_submission.message = submission.message

db.session.add(new_submission)
db.session.commit()

def get_submission(self, submission_id: int) -> SubmissionDataclass:
submission = Submission.query.get(submission_id)
if not submission:
raise ItemNotFoundError(f"submission met id {submission_id} kon niet in de databank gevonden worden")
return submission

def get_submissions_student(self, student_id: int) -> list[SubmissionDataclass]:
student = Student.query.get(student_id)
if not student:
raise ItemNotFoundError(f"student met id {student_id} kon niet in de databank gevonden worden")
submissions: list[SubmissionDataclass] = student.submissions
return submissions

def get_submissions_group(self, group_id: int) -> list[SubmissionDataclass]:
group = Group.query.get(group_id)
if not group:
raise ItemNotFoundError(f"group met id {group_id} kon niet in de databank gevonden worden")
submissions: list[SubmissionDataclass] = group.submissions
return submissions
8 changes: 4 additions & 4 deletions backend/db/interface/SubmissionDAO.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

class SubmissionDAO(ABC):
@abstractmethod
def create_submission(self, submission: SubmissionDataclass, project_id: int, group_id: int):
def create_submission(self, submission: SubmissionDataclass, student_id: int, group_id: int):
"""
Creëert een nieuw SubmissionDataClass in de database en associeert het met een ProjectDataClass en een
Creëert een nieuw SubmissionDataClass in de database en associeert het met een StudentDataclass en een
GroupDataClass.
:param submission: De SubmissionDataClass domeinmodel-instantie die aan de database moet worden toegevoegd.
:param project_id: De identificatie van de ProjectDataClass waarmee het SubmissionDataClass geassocieerd wordt.
:param student_id: De identificatie van de StudentDataclass waarmee het SubmissionDataClass geassocieerd wordt.
:param group_id: De identificatie van de GroupDataClass waarmee het SubmissionDataClass geassocieerd wordt
:raises: ItemNotFoundException: Als er geen ProjectDataClass of GroupDataClass met de opgegeven `project_id` of
:raises: ItemNotFoundException: Als er geen StudentDataclass of GroupDataClass met de opgegeven `student_id` of
`group_id` in de database is.
"""
raise NotImplementedError()
Expand Down

0 comments on commit 8d5e69e

Please sign in to comment.