From 2550c58d993836e531df3bc57020172859e00d0a Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 7 Sep 2023 16:57:58 -0400 Subject: [PATCH] Work on CRUD routes and related SQL --- app/db_sql.py | 6 ++++++ app/models/archive_content_models.py | 3 +-- app/models/archive_models.py | 1 + app/routers/api_crud.py | 12 ++++++------ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/db_sql.py b/app/db_sql.py index 5368fa8..ff03070 100644 --- a/app/db_sql.py +++ b/app/db_sql.py @@ -158,6 +158,9 @@ def sql_insert( INSERT INTO `{table_name}` ({fields_string}) VALUES ({values_string}); """ ) + else: + log.error('The SQL INSERT statement could not be created. Something is missing from the sql_insert call?') + return False log.debug(sql_insert) log.debug(data) @@ -302,6 +305,9 @@ def sql_update( log.warning('Something was missing from the sql_update function call.') return False sql_update = text(sql) + else: + log.error('The SQL UPDATE statement could not be created. Something is missing from the sql_update call?') + return False log.debug(sql_update) diff --git a/app/models/archive_content_models.py b/app/models/archive_content_models.py index 0b8e42b..b98cc11 100644 --- a/app/models/archive_content_models.py +++ b/app/models/archive_content_models.py @@ -57,8 +57,6 @@ class Archive_Content_Base(BaseModel): # xxxx_blue: str = Field(default_factory=testing) hosted_file_path: str = None # '/testing/test-test' - wtf: str = 'HELLO???' - original_datetime: Optional[datetime.datetime] original_datetime_timezone: Optional[str] original_location: Optional[str] @@ -73,6 +71,7 @@ class Archive_Content_Base(BaseModel): enable_from: Optional[datetime.datetime] enable_to: Optional[datetime.datetime] + hide: Optional[bool] priority: Optional[bool] sort: Optional[int] group: Optional[str] diff --git a/app/models/archive_models.py b/app/models/archive_models.py index a406ebb..ff35c94 100644 --- a/app/models/archive_models.py +++ b/app/models/archive_models.py @@ -52,6 +52,7 @@ class Archive_Base(BaseModel): enable_from: Optional[datetime.datetime] = None enable_to: Optional[datetime.datetime] = None + hide: Optional[bool] priority: Optional[bool] sort: Optional[int] group: Optional[str] diff --git a/app/routers/api_crud.py b/app/routers/api_crud.py index 8d60465..86ef698 100644 --- a/app/routers/api_crud.py +++ b/app/routers/api_crud.py @@ -480,7 +480,7 @@ async def patch_obj( obj_dict = crud_data # NOTE: Add a check for the object ID... assuming it is a random ID string for now. Using rm_id_random. That helps with some field names. - if sql_result := sql_update(data=crud_data, table_name=table_name, record_id=obj_id, rm_id_random=True, log_lvl=logging.INFO): + if sql_result := sql_update(data=crud_data, table_name=table_name, record_id=obj_id, rm_id_random=True, log_lvl=logging.DEBUG): log.info('The record was updated.') log.debug(sql_result) @@ -494,9 +494,9 @@ async def patch_obj( log.debug(sql_result) return mk_resp(data=None, status_code=404, status_message='The record was probably not found to be updated.', response=commons.response) else: - log.info('Something unexpected happened while trying to run the SQL UPDATE. The fields or field values passed may not be valid for the table.') + log.info('Something unexpected happened while trying to run the SQL UPDATE. The fields or field values passed may not be valid for the table and or model.') log.debug(sql_result) - return mk_resp(data=False, status_code=400, status_message='Something unexpected happened while trying to runt he SQL UPDATE. The fields or field values passed may not be valid for the table.', response=commons.response) + return mk_resp(data=False, status_code=400, status_message='Something unexpected happened while trying to runt he SQL UPDATE. The fields or field values passed may not be valid for the table and or model.', response=commons.response) # ### END ### API CRUD ### patch_obj() ### @@ -624,7 +624,7 @@ async def post_obj( # NOTE: Add a check for the object ID... assuming it is a random ID string for now. Using rm_id_random. That helps with some field names. if sql_result := sql_insert(data=crud_data, table_name=table_name, rm_id_random=True, log_lvl=logging.INFO): - log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.info('The record was inserted.') log.debug(sql_result) @@ -658,9 +658,9 @@ async def post_obj( log.debug(sql_result) return mk_resp(data=None, status_code=404, status_message='The record was probably not found to be updated.', response=commons.response) else: - log.info('Something unexpected happened while trying to runt he SQL UPDATE. The fields or field values passed may not be valid for the table.') + log.info('Something unexpected happened while trying to runt he SQL UPDATE. The fields or field values passed may not be valid for the table and or model.') log.debug(sql_result) - return mk_resp(data=False, status_code=400, status_message='Something unexpected happened while trying to runt he SQL UPDATE. The fields or field values passed may not be valid for the table.', response=commons.response) + return mk_resp(data=False, status_code=400, status_message='Something unexpected happened while trying to runt he SQL UPDATE. The fields or field values passed may not be valid for the table and or model.', response=commons.response) # ### END ### API CRUD ### post_obj() ###