1717)
1818from app .crud .organization import create_organization , get_organization_by_id
1919from app .utils import APIResponse
20+ from app .core .exception_handlers import NotFoundException
21+
2022
2123router = 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)
5656def 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(
9691def 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