diff --git a/backend/db/implementation/SqlAbstractDAO.py b/backend/db/implementation/SqlAbstractDAO.py index cc7f2c2a..540fbc2b 100644 --- a/backend/db/implementation/SqlAbstractDAO.py +++ b/backend/db/implementation/SqlAbstractDAO.py @@ -1,15 +1,15 @@ from typing import Generic, TypeVar +from pydantic import BaseModel from sqlalchemy import select from sqlalchemy.orm import Session from db.errors.database_errors import ItemNotFoundError from db.extensions import engine from db.models.models import AbstractModel -from domain.models.base_model import JsonRepresentable T = TypeVar("T", bound=AbstractModel) -D = TypeVar("D", bound=JsonRepresentable) +D = TypeVar("D", bound=BaseModel) class SqlAbstractDAO(Generic[T, D]): diff --git a/backend/db/models/models.py b/backend/db/models/models.py index b63d8261..8ce51e0d 100644 --- a/backend/db/models/models.py +++ b/backend/db/models/models.py @@ -3,12 +3,12 @@ from datetime import datetime from typing import Generic, TypeVar +from pydantic import BaseModel from sqlalchemy import Column, ForeignKey, Table from sqlalchemy.orm import Mapped, mapped_column, relationship from db.extensions import Base from domain.models.AdminDataclass import AdminDataclass -from domain.models.base_model import JsonRepresentable from domain.models.GroupDataclass import GroupDataclass from domain.models.ProjectDataclass import ProjectDataclass from domain.models.StudentDataclass import StudentDataclass @@ -17,7 +17,7 @@ from domain.models.TeacherDataclass import TeacherDataclass from domain.models.UserDataclass import UserDataclass -D = TypeVar("D", bound=JsonRepresentable) +D = TypeVar("D", bound=BaseModel) @dataclass() diff --git a/backend/domain/models/GroupDataclass.py b/backend/domain/models/GroupDataclass.py index a67a9ffc..671667e9 100644 --- a/backend/domain/models/GroupDataclass.py +++ b/backend/domain/models/GroupDataclass.py @@ -1,9 +1,9 @@ from dataclasses import dataclass -from domain.models.base_model import JsonRepresentable +from pydantic import BaseModel @dataclass() -class GroupDataclass(JsonRepresentable): +class GroupDataclass(BaseModel): id: int project_id: int diff --git a/backend/domain/models/ProjectDataclass.py b/backend/domain/models/ProjectDataclass.py index 2c45bf36..07826132 100644 --- a/backend/domain/models/ProjectDataclass.py +++ b/backend/domain/models/ProjectDataclass.py @@ -1,11 +1,11 @@ from dataclasses import dataclass from datetime import datetime -from domain.models.base_model import JsonRepresentable +from pydantic import BaseModel, PositiveInt @dataclass() -class ProjectDataclass(JsonRepresentable): +class ProjectDataclass(BaseModel): id: int name: str deadline: datetime @@ -13,5 +13,5 @@ class ProjectDataclass(JsonRepresentable): description: str requirements: str visible: bool - max_students: int + max_students: PositiveInt subject_id: int diff --git a/backend/domain/models/SubjectDataclass.py b/backend/domain/models/SubjectDataclass.py index 92f0a92b..9be302fd 100644 --- a/backend/domain/models/SubjectDataclass.py +++ b/backend/domain/models/SubjectDataclass.py @@ -1,9 +1,9 @@ from dataclasses import dataclass -from domain.models.base_model import JsonRepresentable +from pydantic import BaseModel @dataclass() -class SubjectDataclass(JsonRepresentable): +class SubjectDataclass(BaseModel): id: int name: str diff --git a/backend/domain/models/SubmissionDataclass.py b/backend/domain/models/SubmissionDataclass.py index 5d2641ea..79a85961 100644 --- a/backend/domain/models/SubmissionDataclass.py +++ b/backend/domain/models/SubmissionDataclass.py @@ -2,7 +2,7 @@ from dataclasses import dataclass from datetime import datetime -from domain.models.base_model import JsonRepresentable +from pydantic import BaseModel class SubmissionState(enum.Enum): @@ -12,7 +12,7 @@ class SubmissionState(enum.Enum): @dataclass() -class SubmissionDataclass(JsonRepresentable): +class SubmissionDataclass(BaseModel): id: int date_time: datetime group_id: int diff --git a/backend/domain/models/UserDataclass.py b/backend/domain/models/UserDataclass.py index 1a0696a7..791a864d 100644 --- a/backend/domain/models/UserDataclass.py +++ b/backend/domain/models/UserDataclass.py @@ -1,10 +1,10 @@ from dataclasses import dataclass -from domain.models.base_model import JsonRepresentable +from pydantic import BaseModel, EmailStr @dataclass() -class UserDataclass(JsonRepresentable): +class UserDataclass(BaseModel): id: int name: str - email: str + email: EmailStr diff --git a/backend/domain/models/base_model.py b/backend/domain/models/base_model.py deleted file mode 100644 index 9ab89131..00000000 --- a/backend/domain/models/base_model.py +++ /dev/null @@ -1,8 +0,0 @@ -import dataclasses -from dataclasses import dataclass - - -@dataclass() -class JsonRepresentable: - def to_dict(self) -> dict: - return dataclasses.asdict(self) diff --git a/backend/domain/validation/SubjectValidator.py b/backend/domain/validation/SubjectValidator.py deleted file mode 100644 index 88b2a892..00000000 --- a/backend/domain/validation/SubjectValidator.py +++ /dev/null @@ -1,21 +0,0 @@ -from domain.validation.ValidationResult import ValidationError, ValidationResult, ValidationSuccess - - -class SubjectValidator: - @staticmethod - def validate(json_data: dict) -> ValidationResult: - - name = json_data.get("name") - teacher_id = json_data.get("teacher_id") - - errors: list[str] = [] - if not name: - errors.append("Veld 'name' ontbreekt.") - - if not teacher_id: - errors.append("Veld 'teacher_id' ontbreekt.") - - if len(errors) > 0: - return ValidationError(errors) - - return ValidationSuccess() diff --git a/backend/domain/validation/TeacherValidator.py b/backend/domain/validation/TeacherValidator.py deleted file mode 100644 index 0f57aa15..00000000 --- a/backend/domain/validation/TeacherValidator.py +++ /dev/null @@ -1,18 +0,0 @@ -from domain.validation.ValidationResult import ValidationError, ValidationResult, ValidationSuccess - - -# deze klassen zijn niet meer nodig omdat we gebruik maken van pydantic en FastAPI -class TeacherValidator: - @staticmethod - def validate(json_data: dict) -> ValidationResult: - - name = json_data.get("name") - - errors: list[str] = [] - if not name: - errors.append("Veld 'name' ontbreekt.") - - if len(errors) > 0: - return ValidationError(errors) - - return ValidationSuccess() diff --git a/backend/domain/validation/ValidationResult.py b/backend/domain/validation/ValidationResult.py deleted file mode 100644 index 3ffe7142..00000000 --- a/backend/domain/validation/ValidationResult.py +++ /dev/null @@ -1,24 +0,0 @@ -from abc import ABC, abstractmethod - - -class ValidationResult(ABC): - - errors: list[str] - - @abstractmethod - def __bool__(self) -> bool: - raise NotImplementedError - - -class ValidationSuccess(ValidationResult): - - def __bool__(self) -> bool: - return True - - -class ValidationError(ValidationResult): - def __init__(self, errors: list[str]) -> None: - self.errors = errors - - def __bool__(self) -> bool: - return False diff --git a/backend/requirements.txt b/backend/requirements.txt index 679534f5..dbd63a55 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,6 +1,8 @@ annotated-types==0.6.0 anyio==4.3.0 click==8.1.7 +dnspython==2.6.1 +email_validator==2.1.1 fastapi==0.110.0 greenlet==3.0.3 h11==0.14.0