Code clean up. Working on returning proper 404 vs 400 responses if the results are empty and nothing went wrong.
This commit is contained in:
@@ -95,7 +95,7 @@ async def get_post_obj_li(
|
||||
|
||||
|
||||
# ### BEGIN ### API Post ### get_account_obj_post_list() ###
|
||||
# Working well as of 2021-06-28. Using as a template for other routes.
|
||||
# Updated 2021-12-13
|
||||
@router.get('/account/{account_id}/post/list', response_model=Resp_Body_Base)
|
||||
async def get_account_obj_post_list(
|
||||
account_id: str = Query(..., min_length=1, max_length=22),
|
||||
@@ -122,7 +122,7 @@ async def get_account_obj_post_list(
|
||||
|
||||
response_data = None
|
||||
|
||||
# Updated 2021-06-28
|
||||
# Updated 2021-12-13
|
||||
if post_rec_list_result := get_post_rec_list(
|
||||
for_obj_type = 'account',
|
||||
for_obj_id = account_id,
|
||||
@@ -133,14 +133,11 @@ async def get_account_obj_post_list(
|
||||
post_result_list = []
|
||||
for post_rec in post_rec_list_result:
|
||||
if load_post_result := load_post_obj(
|
||||
post_id = post_rec.get('post_id', None),
|
||||
post_id = post_rec.get('post_id'),
|
||||
limit = limit,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
enabled = enabled,
|
||||
# inc_address = inc_address,
|
||||
# inc_contact = inc_contact,
|
||||
inc_person = inc_person,
|
||||
inc_post_comment_list = inc_post_comment_list,
|
||||
inc_user = inc_user,
|
||||
@@ -149,7 +146,11 @@ async def get_account_obj_post_list(
|
||||
else:
|
||||
post_result_list.append(None)
|
||||
response_data = post_result_list
|
||||
elif isinstance(post_rec_list_result, list) or post_rec_list_result is None: # Empty list or None
|
||||
log.info('No results')
|
||||
return mk_resp(data=False, status_code=404, response=response) # Not Found
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data)
|
||||
|
||||
Reference in New Issue
Block a user