Working on individual module routes

This commit is contained in:
Scott Idem
2021-03-10 15:30:53 -05:00
parent 19222ee946
commit 260091c2ae
4 changed files with 83 additions and 15 deletions

View File

@@ -103,7 +103,7 @@ app.include_router(
) )
app.include_router( app.include_router(
event_exhibit.router, event_exhibit.router,
prefix='/event_exhibit', prefix='/event/exhibit',
tags=['Event Exhibit'], tags=['Event Exhibit'],
#dependencies=[Depends(get_token_header)], #dependencies=[Depends(get_token_header)],
#dependencies=[Depends(get_account_header)], #dependencies=[Depends(get_account_header)],
@@ -111,7 +111,7 @@ app.include_router(
) )
app.include_router( app.include_router(
event_registration.router, event_registration.router,
prefix='/event_registration', prefix='/event/registration',
tags=['Event Registration'], tags=['Event Registration'],
#dependencies=[Depends(get_token_header)], #dependencies=[Depends(get_token_header)],
#dependencies=[Depends(get_account_header)], #dependencies=[Depends(get_account_header)],

View File

@@ -123,4 +123,24 @@ async def delete_account_obj(
obj_type=obj_type, obj_type=obj_type,
obj_id=obj_id, obj_id=obj_id,
) )
return result return result
@router.get('/{obj_id}/cfg', response_model=Resp_Body_Base)
async def get_account_cfg_obj(
obj_id: str = Query(..., min_length=1, max_length=22),
x_account_id: str = Header(...),
by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True,
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
obj_type = 'account_cfg'
result = get_obj_template(
obj_type=obj_type,
obj_id=obj_id,
by_alias=True,
exclude_unset=True,
)
return result

View File

@@ -429,18 +429,22 @@ def patch_obj_template(
def get_obj_li_template( def get_obj_li_template(
obj_type: str = Query(None, max_length=50), obj_type: str = Query(None, max_length=50),
for_obj_type: Optional[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), for_obj_id: Optional[Union[int,str]] = None,
x_account_id: str = Header(...),
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True, exclude_unset: Optional[bool] = True,
): ):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) 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'] table_name_select = obj_type_li[obj_type]['table_name']
if for_obj_type and for_obj_id: 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' 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) 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( def get_obj_template(
obj_type: str = Query(None, max_length=50), 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, by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True, exclude_unset: Optional[bool] = True,
): ):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
debug_data = {} if isinstance(obj_id, int):
debug_data['obj_type'] = obj_type pass
debug_data['obj_id'] = obj_id elif isinstance(obj_id, str):
obj_id_random = obj_id
log.debug(debug_data) 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'] 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 obj_id:
if sql_result := sql_select(table_name=table_name_select, record_id_random=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) log.debug(sql_result)
base_name = obj_type_li[obj_type]['base_name'] base_name = obj_type_li[obj_type]['base_name']
resp_data = base_name(**sql_result).dict(by_alias=by_alias, exclude_unset=exclude_unset) 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: else:
log.debug(sql_result) log.debug(sql_result)
return mk_resp(data=False, status_code=404) return mk_resp(data=False, status_code=404)

View File

@@ -72,6 +72,7 @@ async def patch_contact_obj(
async def get_contact_obj_li( async def get_contact_obj_li(
for_obj_type: Optional[str] = Query(None, min_length=2, max_length=50), for_obj_type: Optional[str] = Query(None, min_length=2, max_length=50),
for_obj_id: Optional[str] = Query(None, min_length=1, max_length=22), for_obj_id: Optional[str] = Query(None, min_length=1, max_length=22),
group: Optional[str] = Query(None, min_length=2, max_length=50),
x_account_id: str = Header(...), x_account_id: str = Header(...),
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True, exclude_unset: Optional[bool] = True,
@@ -80,6 +81,45 @@ async def get_contact_obj_li(
log.debug(locals()) log.debug(locals())
obj_type = 'contact' obj_type = 'contact'
if for_obj_type == 'event_exhibit' and for_obj_id:
#base_name = obj_type_li[obj_type]['base_name']
base_name = Contact_Base
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)
data = {}
data['for_obj_type'] = for_obj_type
data['for_obj_id'] = for_obj_id
data['for_obj_id_random'] = for_obj_id_random
data['group'] = group
if group:
sql = """
SELECT *
FROM `contact` AS contact
WHERE contact.for_type = :for_obj_type AND contact.for_id = :for_obj_id
AND contact.group = :group
"""
else:
sql = """
SELECT *
FROM `contact` AS contact
WHERE contact.for_type = :for_obj_type AND contact.for_id = :for_obj_id
"""
if sql_result := sql_select(data=data, sql=sql, as_list=True):
resp_data_li = []
for record in sql_result:
resp_data = base_name(**record).dict(by_alias=by_alias, exclude_unset=exclude_unset)
resp_data_li.append(resp_data)
return mk_resp(data=resp_data_li)
else:
log.debug(sql_result)
return mk_resp(data=False, status_code=404)
result = get_obj_li_template( result = get_obj_li_template(
obj_type=obj_type, obj_type=obj_type,
for_obj_type=for_obj_type, for_obj_type=for_obj_type,