Working on individual module routes
This commit is contained in:
@@ -103,7 +103,7 @@ app.include_router(
|
||||
)
|
||||
app.include_router(
|
||||
event_exhibit.router,
|
||||
prefix='/event_exhibit',
|
||||
prefix='/event/exhibit',
|
||||
tags=['Event Exhibit'],
|
||||
#dependencies=[Depends(get_token_header)],
|
||||
#dependencies=[Depends(get_account_header)],
|
||||
@@ -111,7 +111,7 @@ app.include_router(
|
||||
)
|
||||
app.include_router(
|
||||
event_registration.router,
|
||||
prefix='/event_registration',
|
||||
prefix='/event/registration',
|
||||
tags=['Event Registration'],
|
||||
#dependencies=[Depends(get_token_header)],
|
||||
#dependencies=[Depends(get_account_header)],
|
||||
|
||||
@@ -124,3 +124,23 @@ async def delete_account_obj(
|
||||
obj_id=obj_id,
|
||||
)
|
||||
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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user