Work on archives and related

This commit is contained in:
Scott Idem
2021-11-02 18:26:16 -04:00
parent 82a6cb4525
commit 94f5f40570
2 changed files with 68 additions and 10 deletions

View File

@@ -114,18 +114,73 @@ async def get_archive_content_obj(
return result return result
@router.delete('/{obj_id}', response_model=Resp_Body_Base) # @router.delete('/{obj_id}', response_model=Resp_Body_Base)
# async def delete_archive_content_obj(
# obj_id: str = Query(..., min_length=1, max_length=22),
# x_account_id: str = Header(...),
# response: Response = Response,
# ):
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(locals())
# obj_type = 'archive_content'
# result = delete_obj_template(
# obj_type=obj_type,
# obj_id=obj_id,
# )
# return result
# ### BEGIN ### API Archive Content ### delete_archive_content_obj() ###
# Updated 2021-11-02
@router.delete('/{archive_content_id}', response_model=Resp_Body_Base)
async def delete_archive_content_obj( async def delete_archive_content_obj(
obj_id: str = Query(..., min_length=1, max_length=22), archive_content_id: str = Query(..., min_length=11, max_length=22),
# hosted_file_id: str = Query(..., min_length=11, max_length=22),
# for_type: str = Query(..., min_length=1, max_length=25),
# for_id: str = Query(..., min_length=11, max_length=22),
delete_hosted_file: bool = False,
x_account_id: str = Header(...), x_account_id: str = Header(...),
response: Response = Response, response: Response = Response,
): ):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
obj_type = 'archive_content' if archive_content_id := redis_lookup_id_random(record_id_random=archive_content_id, table_name='archive_content'): pass
result = delete_obj_template( else: return mk_resp(data=None, status_code=404, response=response)
obj_type=obj_type,
obj_id=obj_id, if archive_content_select_result := sql_select(table_name='archive_content', record_id=archive_content_id):
) log.info(f'Selected Archive Content ID: {archive_content_id}')
return result log.debug(archive_content_select_result)
archive_content_rec = archive_content_select_result
else: return mk_resp(data=False, status_code=500, response=response) # Internal Server Error
if archive_content_delete_result := sql_delete(table_name='archive_content', record_id=archive_content_id):
log.info(f'Deleted Event File ID: {archive_content_id}')
else: return mk_resp(data=False, status_code=500, response=response) # Internal Server Error
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
hosted_file_id = archive_content_rec.get('hosted_file_id')
sql = f"""
DELETE FROM hosted_file_link
WHERE hosted_file_id = :hosted_file_id
AND link_to_type = :for_type
AND link_to_id = :for_id
"""
log.debug(sql)
hosted_file_link_data = {}
hosted_file_link_data['hosted_file_id'] = hosted_file_id
hosted_file_link_data['for_type'] = 'archive_content'
hosted_file_link_data['for_id'] = archive_content_id
log.debug(hosted_file_link_data)
if archive_content_delete_result := sql_delete(sql=sql, data=hosted_file_link_data):
log.info(f'Deleted Hosted File Link. Hosted File ID: {hosted_file_id}, Link To Type: archive_content, Link To ID: {archive_content_id}')
else: return mk_resp(data=False, status_code=500, response=response) # Internal Server Error
return mk_resp(data=True, response=response)
# ### END ### API Archive Content ### delete_archive_content_obj() ###

View File

@@ -162,6 +162,8 @@ async def get_event_file_obj(
# ### END ### API Event File ### get_event_file_obj() ### # ### END ### API Event File ### get_event_file_obj() ###
# ### BEGIN ### API Event File ### delete_event_file_obj() ###
# Updated 2021-11-02
@router.delete('/{event_file_id}', response_model=Resp_Body_Base) @router.delete('/{event_file_id}', response_model=Resp_Body_Base)
async def delete_event_file_obj( async def delete_event_file_obj(
event_file_id: str = Query(..., min_length=11, max_length=22), event_file_id: str = Query(..., min_length=11, max_length=22),
@@ -197,7 +199,7 @@ async def delete_event_file_obj(
hosted_file_link_data = {} hosted_file_link_data = {}
hosted_file_link_data['hosted_file_id'] = hosted_file_id hosted_file_link_data['hosted_file_id'] = hosted_file_id
hosted_file_link_data['for_type'] = for_type hosted_file_link_data['for_type'] = for_type
hosted_file_link_data['for_id'] hosted_file_link_data['for_id'] = for_id
log.debug(hosted_file_link_data) log.debug(hosted_file_link_data)
if event_file_delete_result := sql_delete(sql=sql, data=hosted_file_link_data): if event_file_delete_result := sql_delete(sql=sql, data=hosted_file_link_data):
@@ -205,3 +207,4 @@ async def delete_event_file_obj(
else: return mk_resp(data=False, status_code=500, response=response) # Internal Server Error else: return mk_resp(data=False, status_code=500, response=response) # Internal Server Error
return mk_resp(data=True, response=response) return mk_resp(data=True, response=response)
# ### END ### API Event File ### delete_event_file_obj() ###