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
06ef03c
commit b840cab
Showing
12 changed files
with
104 additions
and
193 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
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 |
---|---|---|
@@ -1,38 +1,39 @@ | ||
from datetime import datetime | ||
|
||
from db.errors.database_errors import ItemNotFoundError | ||
from db.extensions import db | ||
from db.interface.ProjectDAO import ProjectDAO | ||
from db.models.models import Project, Subject | ||
from domain.models.models import ProjectDataclass | ||
from domain.models.ProjectDataclass import ProjectDataclass | ||
|
||
|
||
class SqlProjectDAO(ProjectDAO): | ||
def create_project(self, project: ProjectDataclass, subject_id: int): | ||
subject = Subject.query.get(subject_id) | ||
def create_project(self, subject_id: int, name: str, deadline: datetime, archived: bool, requirements: str, | ||
visible: bool, max_student: int) -> None: | ||
subject: Subject | None = db.session.get(Subject, subject_id) | ||
if not subject: | ||
raise ItemNotFoundError(f"Het subject met id {subject_id} kon niet in de databank gevonden worden") | ||
|
||
new_project = Project() | ||
new_project.subject_id = subject_id | ||
new_project.name = project.name | ||
new_project.deadline = project.deadline | ||
new_project.archived = project.archived | ||
new_project.requirements = project.requirements | ||
new_project.visible = project.visible | ||
new_project.max_students = project.max_students | ||
msg = f"Subject with id {subject_id} not found" | ||
raise ItemNotFoundError(msg) | ||
|
||
new_project: Project = Project(subject_id=subject_id, subject=subject, name=name, deadline=deadline, | ||
archived=archived, requirements=requirements, visible=visible, | ||
max_students=max_student) | ||
|
||
db.session.add(new_project) | ||
db.session.commit() | ||
|
||
project.id = new_project.id | ||
|
||
def get_project(self, project_id: int) -> ProjectDataclass: | ||
project = Project.query.get(project_id) | ||
project: Project | None = db.session.get(Project, ident=project_id) | ||
if not project: | ||
raise ItemNotFoundError(f"Het project met id {project_id} kon niet in de databank gevonden worden") | ||
msg = f"Project with id {project_id} not found" | ||
raise ItemNotFoundError(msg) | ||
return project.to_domain_model() | ||
|
||
def get_projects(self, subject_id: int) -> list[ProjectDataclass]: | ||
subject = Subject.query.get(subject_id) | ||
def get_projects_of_subject(self, subject_id: int) -> list[ProjectDataclass]: | ||
subject: Subject | None = db.session.get(Subject, ident=subject_id) | ||
if not subject: | ||
raise ItemNotFoundError(f"Het subject met id {subject_id} kon niet in de databank gevonden worden") | ||
msg = f"Subject with id {subject_id} not found" | ||
raise ItemNotFoundError(msg) | ||
projects: list[Project] = subject.projects | ||
return [project.to_domain_model() for project in projects] |
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
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 |
---|---|---|
@@ -1,29 +1,25 @@ | ||
from sqlalchemy import select | ||
|
||
from db.errors.database_errors import ItemNotFoundError | ||
from db.extensions import db | ||
from db.interface.UserDAO import UserDAO | ||
from db.models.models import User | ||
from domain.models.models import UserDataclass | ||
from domain.models.UserDataclass import UserDataclass | ||
|
||
|
||
class SqlUserDAO(UserDAO): | ||
def get_user(self, ident: int) -> UserDataclass: | ||
user: User = User.query.get(ident=ident) | ||
|
||
user: User | None = db.session.get(User, ident=ident) | ||
if not user: | ||
raise ItemNotFoundError("UserDataClass with given id not found.") | ||
|
||
msg = f"User with id {ident} not found" | ||
raise ItemNotFoundError(msg) | ||
return user.to_domain_model() | ||
|
||
def get_all_users(self) -> list[UserDataclass]: | ||
users: list[User] = User.query.all() | ||
users: list[User] = list(db.session.scalars(select(User)).all()) | ||
return [user.to_domain_model() for user in users] | ||
|
||
def create_user(self, user: UserDataclass): | ||
new_user: User = User() | ||
new_user.email = user.email | ||
new_user.name = user.name | ||
|
||
def create_user(self, name: str, email: str) -> None: | ||
new_user: User = User(name=name, email=email) | ||
db.session.add(new_user) | ||
db.session.commit() | ||
|
||
user.id = new_user.id |
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
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
Oops, something went wrong.