General clean up. Work on abstracts and websockets

This commit is contained in:
Scott Idem
2023-03-23 19:12:13 -04:00
parent 430a155b75
commit 224aaed969
8 changed files with 435 additions and 48 deletions

View File

@@ -9,9 +9,9 @@ from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select,
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
from app.methods.event_abstract_methods import create_update_event_abstract_obj, load_event_abstract_obj, get_event_abstract_rec_list
from app.methods.event_abstract_methods import create_update_event_abstract_obj, load_event_abstract_obj, get_event_abstract_rec_list, remove_event_abstract_obj
from app.models.event_abstract_models import Event_Abstract_Base
from app.models.event_abstract_models import Event_Abstract_In
from app.models.response_models import Resp_Body_Base, mk_resp
@@ -19,13 +19,19 @@ router = APIRouter()
# ### BEGIN ### API Event Abstract ### post_event_abstract_obj() ###
# Updated 2023-03-20
# Updated 2023-03-22
@router.post('/event/abstract', response_model=Resp_Body_Base)
async def post_event_abstract_obj(
event_abstract_obj: Event_Abstract_Base,
create_sub_obj: bool = False,
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
event_abstract_obj: Event_Abstract_In,
event_id: str = Query(..., min_length=11, max_length=22),
event_person_id: str = Query(..., min_length=11, max_length=22),
# create_sub_obj: bool = False,
# fail_any: bool = True, # Fail if any thing goes wrong for sub objects
return_obj: bool = True,
inc_event_file_list: bool = False,
inc_event_person: bool = False,
inc_event_presentation_list: bool = False,
inc_event_presenter_list: bool = False,
@@ -34,12 +40,19 @@ async def post_event_abstract_obj(
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if event_id := redis_lookup_id_random(record_id_random=event_id, table_name='event'): pass
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The Event ID was invalid or not found.')
if event_person_id := redis_lookup_id_random(record_id_random=event_person_id, table_name='event_person'): pass
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The Event Person ID was invalid or not found.')
# There should probably be a check for the event ID before calling the create function?
if create_event_abstract_obj_result := create_update_event_abstract_obj(
event_abstract_dict_obj = event_abstract_obj,
event_abstract_obj = event_abstract_obj,
event_id = event_abstract_obj.event_id,
create_sub_obj = create_sub_obj,
fail_any = fail_any,
event_person_id = event_abstract_obj.event_person_id,
# create_sub_obj = create_sub_obj,
# fail_any = fail_any,
return_outline = False,
): pass
else: return mk_resp(data=False, status_code=400, response=commons.response, status_message='The event abstract was not created. Check the field names and data types.')
@@ -49,6 +62,8 @@ async def post_event_abstract_obj(
if return_obj:
if load_event_abstract_obj_result := load_event_abstract_obj(
event_abstract_id = event_abstract_id,
inc_event_file_list = inc_event_file_list,
inc_event_person = inc_event_person,
inc_event_presentation_list = inc_event_presentation_list,
inc_event_presenter_list = inc_event_presenter_list,
):
@@ -68,14 +83,18 @@ async def post_event_abstract_obj(
# ### BEGIN ### API Event Abstract ### patch_event_abstract_obj() ###
# Updated 2023-03-20
# Updated 2023-03-22
@router.patch('/event/abstract/{event_abstract_id}', response_model=Resp_Body_Base)
async def patch_event_abstract_obj(
event_abstract_obj: Event_Abstract_Base,
event_abstract_obj: Event_Abstract_In,
event_abstract_id: str = Query(..., min_length=11, max_length=22),
create_sub_obj: bool = False,
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
# create_sub_obj: bool = False,
# fail_any: bool = True, # Fail if any thing goes wrong for sub objects
return_obj: bool = True,
inc_event_file_list: bool = False,
inc_event_person: bool = False,
inc_event_presentation_list: bool = False,
inc_event_presenter_list: bool = False,
@@ -85,14 +104,13 @@ async def patch_event_abstract_obj(
log.debug(locals())
if event_abstract_id := redis_lookup_id_random(record_id_random=event_abstract_id, table_name='event_abstract'): pass
else: return mk_resp(data=None, status_code=404, response=commons.response)
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The Event Abstract ID was invalid or not found.')
if update_event_abstract_obj_result := create_update_event_abstract_obj(
event_abstract_dict_obj = event_abstract_obj,
event_abstract_obj = event_abstract_obj,
event_abstract_id = event_abstract_id,
event_id = event_abstract_obj.event_id,
create_sub_obj = create_sub_obj,
fail_any = fail_any,
# create_sub_obj = create_sub_obj,
# fail_any = fail_any,
return_outline = False,
): pass
else: return mk_resp(data=False, status_code=400, response=commons.response, status_message='The event abstract was not created. Check the field names and data types.')
@@ -101,6 +119,8 @@ async def patch_event_abstract_obj(
if return_obj:
if load_event_abstract_obj_result := load_event_abstract_obj(
event_abstract_id = event_abstract_id,
inc_event_file_list = inc_event_file_list,
inc_event_person = inc_event_person,
inc_event_presentation_list = inc_event_presentation_list,
inc_event_presenter_list = inc_event_presenter_list,
):
@@ -119,13 +139,14 @@ async def patch_event_abstract_obj(
# ### BEGIN ### API Event Abstract ### get_event_abstract_obj() ###
# Updated 2023-03-20
# Updated 2023-03-22
@router.get('/event/abstract/{event_abstract_id}', response_model=Resp_Body_Base)
async def get_event_abstract_obj(
event_abstract_id: str = Query(..., min_length=11, max_length=22),
inc_event_file_list: bool = False,
inc_event_person: bool = False,
# inc_event_person_profile: bool = False,
inc_event_person_profile: bool = True,
inc_event_presentation_list: bool = False,
inc_event_presenter_list: bool = False,
@@ -135,7 +156,7 @@ async def get_event_abstract_obj(
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# time.sleep(.5)
@@ -153,11 +174,15 @@ async def get_event_abstract_obj(
hidden = hidden, # hidden, not_hidden, all
review = review, # ready, not_ready, all
inc_event_file_list = inc_event_file_list,
inc_event_person = inc_event_person,
inc_event_person_profile = inc_event_person_profile,
inc_event_presentation_list = inc_event_presentation_list,
inc_event_presenter_list = inc_event_presenter_list,
):
log.info('Loading successful. Returning result')
event_abstract_obj_result.xyz = 'asdf!!!'
log.debug(event_abstract_obj_result)
return mk_resp(data=event_abstract_obj_result, response=commons.response) # Success
elif isinstance(event_abstract_obj_result, list) or event_abstract_obj_result is None: # Empty list or None
log.info('No results')
@@ -166,3 +191,35 @@ async def get_event_abstract_obj(
log.warning('Likely bad request')
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
# ### END ### API Event Abstract ### get_event_abstract_obj() ###
# ### BEGIN ### API Event Exhibit Tracking ### delete_event_abstract_obj() ###
# Updated 2023-03-22
@router.delete('/event/abstract/{event_abstract_id}', response_model=Resp_Body_Base)
def delete_event_abstract_obj(
event_abstract_id: str = Query(..., min_length=11, max_length=22),
method: str = None, # None, delete, disable, hide
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# ### SECTION ### Secondary data validation
if event_abstract_id := redis_lookup_id_random(record_id_random=event_abstract_id, table_name='event_abstract'): pass
else: return mk_resp(data=None, status_code=404, response=response, status_message='The Event Abstract ID was invalid or not found.')
if event_abstract_obj_result := remove_event_abstract_obj(
event_abstract_id = event_abstract_id,
method = method,
):
log.info('Delete successful. Returning True')
return mk_resp(data=True, response=response) # Success
elif event_abstract_obj_result is None: # None
log.info('No results')
return mk_resp(data=None, status_code=404, response=response) # Not Found
else:
log.warning('Likely bad request')
return mk_resp(data=False, status_code=400, response=response) # Bad Request
# ### END ### API Event Exhibit Tracking ### delete_event_abstract_obj() ###