From 675fd1d522968ec40ccce2a2591980f23e3eceeb Mon Sep 17 00:00:00 2001 From: Mathieu Strypsteen Date: Tue, 5 Mar 2024 13:44:37 +0100 Subject: [PATCH] Use fastapi status --- backend/routes/projects.py | 8 ++++---- backend/routes/subjects.py | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/backend/routes/projects.py b/backend/routes/projects.py index 88000fe3..e73b6574 100644 --- a/backend/routes/projects.py +++ b/backend/routes/projects.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, HTTPException +from fastapi import APIRouter, HTTPException, status from db.errors.database_errors import ItemNotFoundError from domain.logic.SubjectLogic import is_user_authorized_for_subject @@ -23,7 +23,7 @@ def get_subjects(teacher: bool = False) -> list[ProjectDataclass]: for i in subjects: projects += project_dao.get_projects_of_subject(i.id) except ItemNotFoundError as err: - raise HTTPException(status_code=404) from err + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) from err return projects @@ -35,8 +35,8 @@ def get_project(project_id: int) -> ProjectDataclass: try: project = project_dao.get(project_id) except ItemNotFoundError as err: - raise HTTPException(status_code=404) from err + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) from err subject = subject_dao.get(project.subject_id) if not is_user_authorized_for_subject(subject, user, get_dao_provider()): - raise HTTPException(status_code=403) + raise HTTPException(status_code=status.HTTP_403_FORBIDDEN) return project diff --git a/backend/routes/subjects.py b/backend/routes/subjects.py index a48bf7c8..db602a81 100644 --- a/backend/routes/subjects.py +++ b/backend/routes/subjects.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, HTTPException +from fastapi import APIRouter, HTTPException, status from db.errors.database_errors import ItemNotFoundError from domain.logic.SubjectLogic import is_user_authorized_for_subject @@ -19,7 +19,7 @@ def get_subjects(teacher: bool = False) -> list[SubjectDataclass]: return subject_dao.get_subjects_of_teacher(user.id) return subject_dao.get_subjects_of_student(user.id) except ItemNotFoundError as err: - raise HTTPException(status_code=404) from err + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) from err @subjects_router.get("/subjects/{subject_id}") @@ -28,7 +28,7 @@ def get_subject(subject_id: int) -> SubjectDataclass: try: return subject_dao.get(subject_id) except ItemNotFoundError as err: - raise HTTPException(status_code=404) from err + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) from err @subjects_router.get("/subjects/{subject_id}/projects") @@ -38,7 +38,7 @@ def get_subject_projects(subject_id: int) -> list[ProjectDataclass]: try: subject = subject_dao.get(subject_id) if not is_user_authorized_for_subject(subject, get_authenticated_user(), get_dao_provider()): - raise HTTPException(status_code=403) + raise HTTPException(status_code=status.HTTP_403_FORBIDDEN) return project_dao.get_projects_of_subject(subject_id) except ItemNotFoundError as err: - raise HTTPException(status_code=404) from err + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) from err