Improving the CRUD functions and other clean up.
This commit is contained in:
@@ -518,6 +518,8 @@ async def post_obj(
|
||||
# for_obj_type: Optional[str] = Query(None, max_length=50),
|
||||
# for_obj_id: Optional[str] = Query(None, max_length=22),
|
||||
|
||||
return_obj: bool = True,
|
||||
|
||||
commons: Common_Route_Params = Depends(common_route_params),
|
||||
):
|
||||
"""
|
||||
@@ -594,8 +596,10 @@ async def post_obj(
|
||||
return mk_resp(data=False, status_code=400, response=commons.response)
|
||||
|
||||
table_name = obj_type_li[obj_name].get('tbl_name_update')
|
||||
table_name_select = obj_type_li[obj_name].get('table_name')
|
||||
exclude = obj_type_li[obj_name].get('exclude_for_db')
|
||||
|
||||
|
||||
# ### SECTION ### Secondary data validation
|
||||
# if obj_id := redis_lookup_id_random(record_id_random=obj_id, table_name=table_name): pass
|
||||
# else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The object ID was invalid or not found.')
|
||||
@@ -620,14 +624,34 @@ async def post_obj(
|
||||
|
||||
# NOTE: Add a check for the object ID... assuming it is a random ID string for now. Using rm_id_random. That helps with some field names.
|
||||
if sql_result := sql_insert(data=crud_data, table_name=table_name, rm_id_random=True, log_lvl=logging.INFO):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.info('The record was inserted.')
|
||||
log.debug(sql_result)
|
||||
|
||||
resp_data = {}
|
||||
resp_data['table_name'] = table_name
|
||||
resp_data['request_data'] = obj_dict
|
||||
resp_data['obj_id'] = sql_result # The ID should be returned
|
||||
obj_id = sql_result # The ID should be returned
|
||||
resp_data['obj_id'] = obj_id
|
||||
obj_id_random = get_id_random(record_id=obj_id, table_name=table_name)
|
||||
resp_data['obj_id_random'] = obj_id_random
|
||||
|
||||
if return_obj:
|
||||
log.info('Returning object created from POST data')
|
||||
if sql_select_result := sql_select(table_name=table_name_select, record_id=obj_id):
|
||||
log.debug(sql_select_result)
|
||||
|
||||
log.debug(base_name)
|
||||
|
||||
resp_data = base_name(**sql_select_result).dict(by_alias=True, exclude_unset=commons.exclude_unset)
|
||||
|
||||
log.debug(resp_data)
|
||||
|
||||
return mk_resp(data=resp_data, response=commons.response)
|
||||
else:
|
||||
log.debug(sql_select_result)
|
||||
return mk_resp(data=False, status_code=404, response=commons.response)
|
||||
log.info('Returning IDs only created from POST data')
|
||||
return mk_resp(data=resp_data, response=commons.response) #, details=debug_data)
|
||||
elif sql_result == None:
|
||||
log.info('The record was probably not found to be updated.')
|
||||
@@ -759,8 +783,8 @@ def post_obj_template(
|
||||
obj_type: str,
|
||||
data: dict,
|
||||
id_random_length: int = 8, # Added 2023-04-13; need to move away from this
|
||||
return_obj: bool=True,
|
||||
by_alias: bool=True,
|
||||
return_obj: bool = True,
|
||||
by_alias: bool = True,
|
||||
include: Optional[list] = [],
|
||||
exclude: Optional[list] = [],
|
||||
exclude_unset: Optional[bool] = True,
|
||||
|
||||
Reference in New Issue
Block a user