22from typing import List
33from uuid import uuid4
44
5- from fastapi import FastAPI , Request , Response , status
5+ from fastapi import FastAPI , Request , status
66from fastapi .responses import JSONResponse
77from sqlalchemy .orm import sessionmaker , Session
88
@@ -49,8 +49,10 @@ def shutdown():
4949 status_code = status .HTTP_200_OK ,
5050 response_model = List [IdentityMapping ],
5151)
52- async def do_save_mappings (org_id : str , person_id : str , mappings : List [IdentityMapping ]) -> Response :
52+ async def do_save_mappings (org_id : str , person_id : str , mappings : List [IdentityMapping ]) -> List [ IdentityMapping ] :
5353 logger .info (f"CALL RECEIVED TO (POST) /organizations/{ org_id } /persons/{ person_id } /mappings API" )
54+ if service is None :
55+ raise RuntimeError ("Service is not initialized" )
5456 mappings_created : List [IdentityMapping ] = await service .save_mappings (org_id , person_id , mappings )
5557 logger .info (f"Mappings saved successfully for person { person_id } in organization { org_id } " )
5658 return mappings_created
@@ -63,6 +65,8 @@ async def do_save_mappings(org_id: str, person_id: str, mappings: List[IdentityM
6365)
6466async def do_get_mappings (org_id : str , person_id : str ) -> List [IdentityMapping ]:
6567 logger .info (f"CALL RECEIVED TO (GET) /organizations/{ org_id } /persons/{ person_id } /mappings API" )
68+ if service is None :
69+ raise RuntimeError ("Service is not initialized" )
6670 mappings = await service .get_mappings (org_id , person_id )
6771 logger .info (f"Mappings retrieved successfully for person { person_id } in organization { org_id } " )
6872 return mappings
@@ -71,6 +75,8 @@ async def do_get_mappings(org_id: str, person_id: str) -> List[IdentityMapping]:
7175@app .delete ("/organizations/{org_id}/persons/{person_id}/mappings/{mapping_id}" , status_code = status .HTTP_204_NO_CONTENT )
7276async def do_delete_mapping (org_id : str , person_id : str , mapping_id : str ):
7377 logger .info (f"CALL RECEIVED TO (DELETE) /organizations/{ org_id } /persons/{ person_id } /mappings/{ mapping_id } API" )
78+ if service is None :
79+ raise RuntimeError ("Service is not initialized" )
7480 await service .delete_mapping (org_id , person_id , mapping_id )
7581 logger .info (f"Mapping { mapping_id } deleted successfully for person { person_id } in organization { org_id } " )
7682
0 commit comments