Working on file uploads and event files.
This commit is contained in:
@@ -20,24 +20,24 @@ router = APIRouter()
|
||||
|
||||
@router.post('', response_model=Resp_Body_Base)
|
||||
async def post_event_file_obj(
|
||||
obj: Event_File_Base,
|
||||
event_file_obj: Event_File_Base,
|
||||
x_account_id: str = Header(...),
|
||||
return_obj: Optional[bool] = True,
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
obj_type = 'event_file'
|
||||
obj_data_dict = obj.dict(by_alias=False, exclude_unset=True)
|
||||
event_file_obj_data_dict = event_file_obj.dict(by_alias=False, exclude_unset=True)
|
||||
result = post_obj_template(
|
||||
obj_type=obj_type,
|
||||
data=obj_data_dict,
|
||||
return_obj=True,
|
||||
by_alias=True,
|
||||
exclude_unset=True,
|
||||
obj_type = obj_type,
|
||||
data = event_file_obj_data_dict,
|
||||
return_obj = True,
|
||||
by_alias = True,
|
||||
exclude_unset = True,
|
||||
)
|
||||
return result
|
||||
|
||||
@@ -52,7 +52,7 @@ async def patch_event_file_obj(
|
||||
exclude_unset: Optional[bool] = True,
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
obj_type = 'event_file'
|
||||
@@ -70,6 +70,62 @@ async def patch_event_file_obj(
|
||||
return result
|
||||
|
||||
|
||||
# ### BEGIN ### API Event File ### get_event_file_lookup() ###
|
||||
# Updated 2021-10-06
|
||||
@router.get('/lookup', response_model=Resp_Body_Base)
|
||||
async def event_file_lookup(
|
||||
hosted_file_id: str = Query(..., min_length=11, max_length=22),
|
||||
for_type: str = Query(..., min_length=5, max_length=15),
|
||||
for_id: str = Query(..., min_length=11, max_length=22),
|
||||
inc_hosted_file: bool = False,
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if hosted_file_id := redis_lookup_id_random(record_id_random=hosted_file_id, table_name='hosted_file'): pass
|
||||
else: return mk_resp(data=False, status_code=404, status_message=f'Hosted File ID was not found. Hosted File ID: {hosted_file_id}', response=response) # Not Found
|
||||
|
||||
if for_id := redis_lookup_id_random(record_id_random=for_id, table_name=for_type): pass
|
||||
else: return mk_resp(data=False, status_code=404, status_message=f'For ID was not found. For Type: {for_type}, For ID: {for_id}', response=response) # Not Found
|
||||
|
||||
data = {}
|
||||
data['hosted_file_id'] = hosted_file_id
|
||||
data['for_type'] = for_type
|
||||
data['for_id'] = for_id
|
||||
log.debug(data)
|
||||
|
||||
sql = f"""
|
||||
SELECT id AS 'event_file_id', id_random AS 'event_file_id_random'
|
||||
FROM `event_file` AS `event_file`
|
||||
WHERE `event_file`.hosted_file_id = :hosted_file_id
|
||||
AND `event_file`.for_type = :for_type
|
||||
AND `event_file`.for_id = :for_id
|
||||
"""
|
||||
log.debug(sql)
|
||||
|
||||
if event_file_obj_result := sql_select(data=data, sql=sql):
|
||||
log.debug(event_file_obj_result)
|
||||
event_file_id = event_file_obj_result.get('event_file_id', None)
|
||||
if event_file_obj := load_event_file_obj(
|
||||
event_file_id = event_file_id,
|
||||
inc_hosted_file = inc_hosted_file,
|
||||
enabled = 'all', # NOTE: This should not be hardcoded
|
||||
model_as_dict = False,
|
||||
):
|
||||
event_file_dict = event_file_obj.dict(by_alias = by_alias, exclude_unset=exclude_unset)
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
||||
else:
|
||||
log.debug(event_file_obj_result)
|
||||
return mk_resp(data=None, status_code=404, status_message=f'An Event File was not found. Hosted File ID: {hosted_file_id}, For Type: {for_type}, For ID: {for_id}', response=response) # Not Found
|
||||
return mk_resp(data=event_file_dict, response=response)
|
||||
# ### END ### API Event File ### get_event_file_lookup() ###
|
||||
|
||||
|
||||
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
||||
async def delete_event_file_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
|
||||
@@ -133,10 +133,10 @@ async def upload_files(
|
||||
|
||||
# NOTE: Currently sql_insert does not handel all successful inserts correctly. If there is not an autonum ID then it will return 0 as the ID.
|
||||
if create_hosted_file_link(
|
||||
account_id=account_id,
|
||||
hosted_file_id=hosted_file_id,
|
||||
link_to_type=link_to_type,
|
||||
link_to_id=link_to_id,
|
||||
account_id = account_id,
|
||||
hosted_file_id = hosted_file_id,
|
||||
link_to_type = link_to_type,
|
||||
link_to_id = link_to_id,
|
||||
): pass # This if statement should be improved
|
||||
else:
|
||||
# This if statement should be improved
|
||||
|
||||
Reference in New Issue
Block a user