Working on individual module routes
This commit is contained in:
@@ -429,18 +429,22 @@ def patch_obj_template(
|
||||
def get_obj_li_template(
|
||||
obj_type: str = Query(None, max_length=50),
|
||||
for_obj_type: Optional[str] = Query(None, max_length=50),
|
||||
for_obj_id: Optional[str] = Query(None, max_length=22),
|
||||
x_account_id: str = Header(...),
|
||||
for_obj_id: Optional[Union[int,str]] = None,
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if isinstance(for_obj_id, int):
|
||||
pass
|
||||
elif isinstance(for_obj_id, str):
|
||||
for_obj_id_random = for_obj_id
|
||||
for_obj_id = redis_lookup_id_random(record_id_random=for_obj_id_random, table_name=for_obj_type)
|
||||
|
||||
table_name_select = obj_type_li[obj_type]['table_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)
|
||||
field_name = f'{for_obj_type}_id'
|
||||
|
||||
sql_result = sql_select(table_name=table_name_select, field_name=field_name, field_value=for_obj_id)
|
||||
@@ -461,29 +465,33 @@ def get_obj_li_template(
|
||||
|
||||
def get_obj_template(
|
||||
obj_type: str = Query(None, max_length=50),
|
||||
obj_id: str = Query(None, max_length=22),
|
||||
obj_id: Optional[Union[int,str]] = None,
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
debug_data = {}
|
||||
debug_data['obj_type'] = obj_type
|
||||
debug_data['obj_id'] = obj_id
|
||||
|
||||
log.debug(debug_data)
|
||||
if isinstance(obj_id, int):
|
||||
pass
|
||||
elif isinstance(obj_id, str):
|
||||
obj_id_random = obj_id
|
||||
obj_id = redis_lookup_id_random(record_id_random=obj_id_random, table_name=obj_type)
|
||||
|
||||
table_name_select = obj_type_li[obj_type]['table_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_select, record_id_random=obj_id):
|
||||
if obj_id:
|
||||
sql_result = sql_select(table_name=table_name_select, record_id=obj_id)
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400)
|
||||
|
||||
if sql_result:
|
||||
log.debug(sql_result)
|
||||
|
||||
base_name = obj_type_li[obj_type]['base_name']
|
||||
resp_data = base_name(**sql_result).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
|
||||
return mk_resp(data=resp_data) #, details=debug_data)
|
||||
return mk_resp(data=resp_data)
|
||||
else:
|
||||
log.debug(sql_result)
|
||||
return mk_resp(data=False, status_code=404)
|
||||
|
||||
Reference in New Issue
Block a user