Code clean up. Working on returning proper 404 vs 400 responses if the results are empty and nothing went wrong.

This commit is contained in:
Scott Idem
2021-12-13 17:02:21 -05:00
parent 2ef53d7a51
commit 133cfab42f
10 changed files with 131 additions and 100 deletions

View File

@@ -5,7 +5,7 @@ from typing import Dict, List, Optional, Set, Union
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
from app.lib_general import log, logging
from app.lib_general import log, logging, logger_reset
# from app.methods.event_methods import load_event_obj
# from app.methods.event_device_methods import load_event_device_obj
@@ -18,6 +18,7 @@ from app.models.event_location_models import Event_Location_Base
# ### BEGIN ### API Event Location Methods ### load_event_location_obj() ###
@logger_reset
def load_event_location_obj(
event_location_id: int|str,
inc_event_device_list: bool = False,
@@ -37,7 +38,7 @@ def load_event_location_obj(
exclude_unset: bool = True,
model_as_dict: bool = False,
) -> Event_Location_Base|bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if event_location_id := redis_lookup_id_random(record_id_random=event_location_id, table_name='event_location'): pass
@@ -206,6 +207,8 @@ def load_event_location_obj(
# ### BEGIN ### API Event Location Methods ### get_event_location_rec_list() ###
# Updated 2021-12-13
@logger_reset
def get_event_location_rec_list(
event_id: str,
enabled: str = 'enabled', # enabled, disabled, all
@@ -261,16 +264,16 @@ def get_event_location_rec_list(
ORDER BY `event_location`.priority DESC, `event_location`.sort ASC, `event_location`.name ASC, `event_location`.created_on DESC, `event_location`.updated_on DESC
{sql_limit};
"""
log.debug(sql)
if event_location_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
if event_location_rec_li_result := sql_select(data=data, sql=sql):
log.info('Got a list result')
event_location_rec_li = event_location_rec_li_result
else:
event_location_rec_li = []
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
else: # None or False
log.info('No results or something went wrong')
event_location_rec_li = event_location_rec_li_result # []
log.debug(event_location_rec_li_result)
log.debug(type(event_location_rec_li))
log.debug(len(event_location_rec_li))
return event_location_rec_li
# ### END ### API Event Location Methods ### get_event_location_rec_list() ###