diff --git a/app/routers/api_crud.py b/app/routers/api_crud.py index 1bfd50d..1fbb9e8 100644 --- a/app/routers/api_crud.py +++ b/app/routers/api_crud.py @@ -284,6 +284,11 @@ async def get_obj_li( else: table_name = obj_type_li[obj_name]['table_name'] + if use_alt_base: + base_name = obj_type_li[obj_name]['base_name_alt'] + else: + base_name = obj_type_li[obj_name]['base_name'] + if for_obj_type and for_obj_id: for_obj_id = redis_lookup_id_random(record_id_random=for_obj_id, table_name=for_obj_type) log.debug(f'for_obj_type: {for_obj_type}') @@ -329,11 +334,6 @@ async def get_obj_li( # log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(sql_result) - if use_alt_base: - base_name = obj_type_li[obj_name]['base_name_alt'] - else: - base_name = obj_type_li[obj_name]['base_name'] - if sql_result: if isinstance(sql_result, list): resp_data_li = [] @@ -358,6 +358,9 @@ async def get_obj( obj_type_l3: str=None, obj_id: str=None, + use_alt_table: bool = False, # NOTE: This will use table_name_alt if they exist. -2023-12-01 + use_alt_base: bool = False, # NOTE: This will use base_name_alt if they exist. -2023-12-01 + # for_obj_type: Optional[str] = Query(None, max_length=50), # NOTE: This is not currently used. It is here for future use. # for_obj_id: Optional[str] = Query(None, max_length=22), # NOTE: This is not currently used. It is here for future use. @@ -392,8 +395,8 @@ async def get_obj( debug_data['obj_type_l2'] = obj_type_l2 debug_data['obj_type_l3'] = obj_type_l3 debug_data['obj_id'] = obj_id - # debug_data['for_obj_type'] = for_obj_type - # debug_data['for_obj_id'] = for_obj_id + debug_data['use_alt_table'] = use_alt_table + debug_data['use_alt_base'] = use_alt_base log.debug(debug_data) @@ -423,13 +426,20 @@ async def get_obj( log.warning('We should not be here') return mk_resp(data=False, status_code=400, response=commons.response) - table_name = obj_type_li[obj_name]['table_name'] + if use_alt_table: + table_name = obj_type_li[obj_name]['table_name_alt'] + else: + table_name = obj_type_li[obj_name]['table_name'] + + if use_alt_base: + base_name = obj_type_li[obj_name]['base_name_alt'] + else: + base_name = obj_type_li[obj_name]['base_name'] # NOTE: Add a check for the object ID... assuming it is a random ID string for now. if sql_result := sql_select(table_name=table_name, record_id_random=obj_id): log.debug(sql_result) - base_name = obj_type_li[obj_name]['base_name'] resp_data = base_name(**sql_result).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset) return mk_resp(data=resp_data, response=commons.response) #, details=debug_data)