Skip to content

Commit 59a7847

Browse files
committed
refactored org code
1 parent 9c12782 commit 59a7847

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

backend/app/api/routes/organization.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
)
1818
from app.crud.organization import create_organization, get_organization_by_id
1919
from app.utils import APIResponse
20+
from app.core.exception_handlers import NotFoundException
21+
2022

2123
router = APIRouter(prefix="/organizations", tags=["organizations"])
2224

2325

24-
# Retrieve organizations
2526
@router.get(
2627
"/",
2728
dependencies=[Depends(get_current_active_superuser)],
@@ -37,7 +38,6 @@ def read_organizations(session: SessionDep, skip: int = 0, limit: int = 100):
3738
return APIResponse.success_response(organizations)
3839

3940

40-
# Create a new organization
4141
@router.post(
4242
"/",
4343
dependencies=[Depends(get_current_active_superuser)],
@@ -54,16 +54,12 @@ def create_new_organization(*, session: SessionDep, org_in: OrganizationCreate):
5454
response_model=APIResponse[OrganizationPublic],
5555
)
5656
def read_organization(*, session: SessionDep, org_id: int):
57-
"""
58-
Retrieve an organization by ID.
59-
"""
6057
org = get_organization_by_id(session=session, org_id=org_id)
6158
if org is None:
62-
raise HTTPException(status_code=404, detail="Organization not found")
59+
raise NotFoundException("Organization not found")
6360
return APIResponse.success_response(org)
6461

6562

66-
# Update an organization
6763
@router.patch(
6864
"/{org_id}",
6965
dependencies=[Depends(get_current_active_superuser)],
@@ -74,7 +70,7 @@ def update_organization(
7470
):
7571
org = get_organization_by_id(session=session, org_id=org_id)
7672
if org is None:
77-
raise HTTPException(status_code=404, detail="Organization not found")
73+
raise NotFoundException("Organization not found")
7874

7975
org_data = org_in.model_dump(exclude_unset=True)
8076
org = org.model_copy(update=org_data)
@@ -86,7 +82,6 @@ def update_organization(
8682
return APIResponse.success_response(org)
8783

8884

89-
# Delete an organization
9085
@router.delete(
9186
"/{org_id}",
9287
dependencies=[Depends(get_current_active_superuser)],
@@ -96,7 +91,7 @@ def update_organization(
9691
def delete_organization(session: SessionDep, org_id: int):
9792
org = get_organization_by_id(session=session, org_id=org_id)
9893
if org is None:
99-
raise HTTPException(status_code=404, detail="Organization not found")
94+
raise NotFoundException("Organization not found")
10095

10196
session.delete(org)
10297
session.commit()

0 commit comments

Comments
 (0)