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.
Merge pull request #53 from SELab-2/verwijderen-daos
Verwijderen daos
- Loading branch information
Showing
52 changed files
with
746 additions
and
970 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,59 @@ | ||
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.project import project_router | ||
from routes.student import student_router | ||
from routes.subject import subject_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") | ||
app.include_router(project_router, prefix="/api") | ||
app.include_router(subject_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") |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.