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

@@ -72,6 +72,7 @@ async def patch_contact_obj(
async def get_contact_obj_li(
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),
group: Optional[str] = Query(None, min_length=2, max_length=50),
x_account_id: str = Header(...),
by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True,
@@ -80,6 +81,45 @@ async def get_contact_obj_li(
log.debug(locals())
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(
obj_type=obj_type,
for_obj_type=for_obj_type,