Work on CRUD routes and related SQL

This commit is contained in:
Scott Idem
2023-09-07 16:57:58 -04:00
parent 116cdd4a45
commit 2550c58d99
4 changed files with 14 additions and 8 deletions

View File

@@ -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)

View File

@@ -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]

View File

@@ -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]

View File

@@ -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() ###