Improve data store record retrieval.
This commit is contained in:
@@ -55,6 +55,8 @@ def load_data_store_obj(
|
||||
def load_data_store_obj_w_code(
|
||||
account_id: int,
|
||||
code: str,
|
||||
for_type: int = None,
|
||||
for_id: int = None,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
limit: int = 1,
|
||||
offset: int = 0,
|
||||
@@ -68,9 +70,18 @@ def load_data_store_obj_w_code(
|
||||
data = {}
|
||||
data['account_id'] = account_id
|
||||
data['code'] = code
|
||||
data['for_type'] = for_type
|
||||
data['for_id'] = for_id
|
||||
|
||||
log.debug(data)
|
||||
# log.warning(f'Can we get past this?????????? {code}')
|
||||
# if for_id := redis_lookup_id_random(record_id_random=for_id, table_name=for_type): pass
|
||||
# else: return False
|
||||
|
||||
if for_type and for_id:
|
||||
sql_for_type_id = 'AND `data_store`.for_type = :for_type AND `data_store`.for_id = :for_id'
|
||||
else:
|
||||
sql_for_type_id = 'AND `data_store`.for_type IS NULL AND `data_store`.for_id IS NULL'
|
||||
|
||||
sql_enabled, data['enable'] = sql_enable_part(table_name='data_store', enabled=enabled) # Reasonably safe return str and bool
|
||||
sql_limit = sql_limit_offset_part(limit=limit, offset=offset) # Reasonably safe return str
|
||||
@@ -87,6 +98,7 @@ def load_data_store_obj_w_code(
|
||||
OR `data_store`.account_id IS NULL
|
||||
)
|
||||
AND `data_store`.code = :code
|
||||
{sql_for_type_id}
|
||||
{sql_enabled}
|
||||
ORDER BY `data_store`.account_id DESC, `data_store`.created_on DESC, `data_store`.updated_on DESC
|
||||
{sql_limit};
|
||||
|
||||
@@ -173,7 +173,7 @@ def get_event_abstract_rec_list(
|
||||
|
||||
if event_id:
|
||||
data['event_id'] = event_id
|
||||
sql_event_id = f'AND `event_abstract`.event_id = :event_id'
|
||||
sql_event_id = f'`event_abstract`.event_id = :event_id'
|
||||
else: sql_event_id = '1=1'
|
||||
|
||||
if event_person_id:
|
||||
|
||||
@@ -156,9 +156,9 @@ class Event_Abstract_Base_New(Core_Std_Obj_Base):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# id_random: Optional[str] = Field(
|
||||
# alias = 'event_abstract_id_random',
|
||||
# )
|
||||
id_random: Optional[str] = Field(
|
||||
alias = 'event_abstract_id_random',
|
||||
)
|
||||
|
||||
event_id_random: Optional[str]
|
||||
event_id: Optional[int]
|
||||
|
||||
@@ -136,24 +136,35 @@ async def get_data_store_obj(
|
||||
|
||||
|
||||
# ### BEGIN ### API Data Store ### get_data_store_obj_w_code() ###
|
||||
# Updated 2022-03-11
|
||||
# NOTE: Adding some explanation because this is not quickly obvious how it fully works.
|
||||
# The look up order starts with a required data_store_code. Then the first result that matches the most specific method. The for_type and for_id fields are not required. I think it makes the most sense to be a part of the URL path, not the GET params. Either should work with no problem though.
|
||||
# Lookup using: for_type and for_id > account_id > data_store_code
|
||||
# This is a nice way to have global default data along with account and object specific data.
|
||||
# Updated 2023-05-22
|
||||
@router.get('/data_store/code/{data_store_code}/{for_type}/{for_id}', response_model=Resp_Body_Base)
|
||||
@router.get('/data_store/code/{data_store_code}', response_model=Resp_Body_Base)
|
||||
async def get_data_store_obj_w_code(
|
||||
data_store_code: str = Query(..., min_length=3, max_length=50),
|
||||
for_type: Optional[str] = Query(None, min_length=1, max_length=25),
|
||||
for_id: Optional[str] = Query(None, min_length=11, max_length=22),
|
||||
|
||||
commons: Common_Route_Params = Depends(common_route_params),
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# ### SECTION ### Secondary data validation
|
||||
# None
|
||||
if for_type and for_id:
|
||||
if for_id := redis_lookup_id_random(record_id_random=for_id, table_name=for_type): pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The for type and ID was invalid or not found.')
|
||||
|
||||
# NOTE: Currently this returns a list: load_data_store_obj_w_code()
|
||||
# NOTE: Only the first sorted record is needed
|
||||
if data_store_obj_result := load_data_store_obj_w_code(
|
||||
account_id = commons.x_account_id,
|
||||
code = data_store_code,
|
||||
for_type = for_type,
|
||||
for_id = for_id,
|
||||
limit = 1, # commons.limit,
|
||||
enabled = commons.enabled,
|
||||
):
|
||||
|
||||
@@ -193,6 +193,71 @@ async def get_event_abstract_obj(
|
||||
# ### END ### API Event Abstract ### get_event_abstract_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Abstract ### get_event_id_event_abstract_obj_li() ###
|
||||
# Updated 2023-05-22
|
||||
@router.get('/event/{event_id}/event/abstract/list', response_model=Resp_Body_Base)
|
||||
async def get_event_id_event_abstract_obj_li(
|
||||
event_id: str = Query(..., min_length=11, max_length=22),
|
||||
|
||||
# inc_address: bool = False,
|
||||
# inc_contact: bool = False,
|
||||
# inc_event_file_list: bool = False,
|
||||
inc_event_person: bool = False, # Intended for event_presenter
|
||||
# inc_file_count: bool = False, # NOTE: file counts are from separate views
|
||||
# inc_poc_event_person: bool = False,
|
||||
|
||||
approved: str = 'all', # approved, not_approved, all
|
||||
hidden: str = 'not_hidden', # hidden, not_hidden, all
|
||||
review: str = 'all', # hidden, not_hidden, all
|
||||
|
||||
commons: Common_Route_Params = Depends(common_route_params),
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if event_id := redis_lookup_id_random(record_id_random=event_id, table_name='event'): pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response)
|
||||
|
||||
# Updated 2023-05-22
|
||||
if event_abstract_rec_list_result := get_event_abstract_rec_list(
|
||||
event_id = event_id,
|
||||
|
||||
# review = review, # ready, not_ready, all
|
||||
approved = approved, # approve(d), not_approved, all
|
||||
# hidden = hidden, # hidden, not_hidden, all
|
||||
|
||||
enabled = commons.enabled,
|
||||
limit = commons.limit,
|
||||
offset = commons.offset,
|
||||
):
|
||||
event_abstract_result_list = []
|
||||
for event_abstract_rec in event_abstract_rec_list_result:
|
||||
if load_event_abstract_result := load_event_abstract_obj(
|
||||
event_abstract_id = event_abstract_rec.get('event_abstract_id', None),
|
||||
|
||||
# review = review,
|
||||
# approved = approved,
|
||||
hidden = hidden,
|
||||
|
||||
enabled = commons.enabled,
|
||||
limit = commons.limit,
|
||||
inc_event_person = inc_event_person,
|
||||
):
|
||||
event_abstract_result_list.append(load_event_abstract_result)
|
||||
else:
|
||||
event_abstract_result_list.append(None)
|
||||
response_data = event_abstract_result_list
|
||||
elif isinstance(event_abstract_rec_list_result, list) or event_abstract_rec_list_result is None: # Empty list or None
|
||||
log.info('No results')
|
||||
return mk_resp(data=False, status_code=404, response=commons.response) # Not Found
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data, response=commons.response)
|
||||
# ### END ### API Event Abstract ### get_event_id_event_abstract_obj_li() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Abstract ### delete_event_abstract_obj() ###
|
||||
# Updated 2023-03-22
|
||||
@router.delete('/event/abstract/{event_abstract_id}', response_model=Resp_Body_Base)
|
||||
|
||||
Reference in New Issue
Block a user