This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9ab3d5
commit 8d5e69e
Showing
3 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters