Work on simplifying functions. ID lookups are better. Person and User related is being worked on.
This commit is contained in:
@@ -20,7 +20,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
# ### BEGIN ### API Person Routers ### post_person_obj() ###
|
||||
# Updated 2022-01-05
|
||||
# Updated 2022-01-06
|
||||
@router.post('/person', response_model=Resp_Body_Base)
|
||||
async def post_person_obj(
|
||||
person_obj: Person_Base,
|
||||
@@ -33,6 +33,20 @@ async def post_person_obj(
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# ### SECTION ### Secondary data validation
|
||||
if contact_id := redis_lookup_id_random(record_id_random=contact_id, table_name='contact'): pass
|
||||
elif contact_id is None: pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The contact ID was invalid or not found.')
|
||||
|
||||
if organization_id := redis_lookup_id_random(record_id_random=organization_id, table_name='organization'): pass
|
||||
elif organization_id is None: pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The organization ID was invalid or not found.')
|
||||
|
||||
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
|
||||
elif user_id is None: pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The user ID was invalid or not found.')
|
||||
|
||||
# ### SECTION ### Process data
|
||||
if person_id := create_person_kiss(
|
||||
account_id = commons.x_account_id,
|
||||
person_dict_obj = person_obj,
|
||||
@@ -42,8 +56,9 @@ async def post_person_obj(
|
||||
): pass
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
return mk_resp(data=False, status_code=400, response=commons.response, status_message='Something failed while processing the data.') # Bad Request
|
||||
|
||||
# ### SECTION ### Return successful results
|
||||
if return_obj:
|
||||
person_obj = load_person_obj(
|
||||
person_id = person_id,
|
||||
@@ -60,7 +75,7 @@ async def post_person_obj(
|
||||
|
||||
|
||||
# ### BEGIN ### API Person Routers ### patch_person_obj() ###
|
||||
# Updated 2022-01-05
|
||||
# Updated 2022-01-06
|
||||
@router.patch('/person/{person_id}', response_model=Resp_Body_Base)
|
||||
async def patch_person_obj(
|
||||
person_obj: Person_Base,
|
||||
@@ -71,10 +86,28 @@ async def patch_person_obj(
|
||||
return_obj: Optional[bool] = True,
|
||||
commons: Common_Route_Params = Depends(common_route_params),
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# ### SECTION ### Secondary data validation
|
||||
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The person ID was invalid or not found.')
|
||||
|
||||
if contact_id := redis_lookup_id_random(record_id_random=contact_id, table_name='contact'): pass
|
||||
elif contact_id is None: pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The contact ID was invalid or not found.')
|
||||
|
||||
if organization_id := redis_lookup_id_random(record_id_random=organization_id, table_name='organization'): pass
|
||||
elif organization_id is None: pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The organization ID was invalid or not found.')
|
||||
|
||||
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
|
||||
elif user_id is None: pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The user ID was invalid or not found.')
|
||||
|
||||
# ### SECTION ### Process data
|
||||
if person_update_result := update_person_kiss(
|
||||
person_id = person_id,
|
||||
person_dict_obj = person_obj,
|
||||
contact_id = contact_id,
|
||||
organization_id = organization_id,
|
||||
@@ -82,8 +115,9 @@ async def patch_person_obj(
|
||||
): pass
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
return mk_resp(data=False, status_code=400, response=commons.response, status_message='Something failed while processing the data.') # Bad Request
|
||||
|
||||
# ### SECTION ### Return successful results
|
||||
if return_obj:
|
||||
person_obj = load_person_obj(
|
||||
person_id = person_id,
|
||||
|
||||
Reference in New Issue
Block a user