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

Commit

Permalink
Volledige refactor DAOs #45
Browse files Browse the repository at this point in the history
  • Loading branch information
lbarraga committed Mar 6, 2024
1 parent a5e833d commit 171a173
Show file tree
Hide file tree
Showing 50 changed files with 499 additions and 1,022 deletions.
49 changes: 44 additions & 5 deletions backend/app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,55 @@
import uvicorn
from fastapi import FastAPI
from starlette import status
from starlette.requests import Request
from starlette.responses import JSONResponse

from routes.projects import projects_router
from routes.subjects import subjects_router
from routes.users import users_router
from db.errors.database_errors import ActionAlreadyPerformedError, ItemNotFoundError
from routes.errors.authentication import InvalidRoleCredentialsError, StudentNotEnrolledError
from routes.student import student_router
from routes.teacher import teacher_router
from routes.user import users_router

app = FastAPI()

# Koppel routes uit andere modules.
app.include_router(subjects_router, prefix="/api")
app.include_router(student_router, prefix="/api")
app.include_router(teacher_router, prefix="/api")
app.include_router(users_router, prefix="/api")
app.include_router(projects_router, prefix="/api")


# Koppel de exception handlers
@app.exception_handler(InvalidRoleCredentialsError)
def invalid_admin_credentials_error_handler(request: Request, exc: InvalidRoleCredentialsError) -> JSONResponse:
return JSONResponse(
status_code=status.HTTP_403_FORBIDDEN,
content={"message": exc.ERROR_MESSAGE},
)


@app.exception_handler(ItemNotFoundError)
def item_not_found_error_handler(request: Request, exc: ItemNotFoundError) -> JSONResponse:
return JSONResponse(
status_code=status.HTTP_404_NOT_FOUND,
content={"detail": str(exc)},
)


@app.exception_handler(StudentNotEnrolledError)
def student_already_enrolled_error_handler(request: Request, exc: StudentNotEnrolledError) -> JSONResponse:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content={"detail": str(exc)},
)


@app.exception_handler(ActionAlreadyPerformedError)
def action_already_performed_error_handler(request: Request, exc: ActionAlreadyPerformedError) -> JSONResponse:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content={"detail": str(exc)},
)


if __name__ == "__main__":
uvicorn.run("app:app")
2 changes: 1 addition & 1 deletion backend/db/errors/database_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ def __init__(self, message: str) -> None:
super().__init__(message)


class UniqueConstraintError(Exception):
class ActionAlreadyPerformedError(Exception):
def __init__(self, message: str) -> None:
super().__init__(message)
32 changes: 0 additions & 32 deletions backend/db/implementation/SqlAbstractDAO.py

This file was deleted.

24 changes: 0 additions & 24 deletions backend/db/implementation/SqlAdminDAO.py

This file was deleted.

43 changes: 0 additions & 43 deletions backend/db/implementation/SqlDAOProvider.py

This file was deleted.

69 changes: 0 additions & 69 deletions backend/db/implementation/SqlGroupDAO.py

This file was deleted.

56 changes: 0 additions & 56 deletions backend/db/implementation/SqlProjectDAO.py

This file was deleted.

24 changes: 0 additions & 24 deletions backend/db/implementation/SqlStudentDAO.py

This file was deleted.

74 changes: 0 additions & 74 deletions backend/db/implementation/SqlSubjectDAO.py

This file was deleted.

Loading

0 comments on commit 171a173

Please sign in to comment.