General clean up. Workon event abstracts.

This commit is contained in:
Scott Idem
2023-03-20 19:39:41 -04:00
parent 02fa7225ac
commit df26128ce4
10 changed files with 589 additions and 20 deletions

View File

@@ -0,0 +1,168 @@
import datetime, json
from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, Response, status
from pydantic import BaseModel, EmailStr, Field
from typing import Dict, List, Optional, Set, Union
from app.lib_general import log, logging, common_route_params, Common_Route_Params
from app.config import settings
from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, get_id_random, redis_lookup_id_random
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.models.event_abstract_models import Event_Abstract_Base
from app.models.response_models import Resp_Body_Base, mk_resp
router = APIRouter()
# ### BEGIN ### API Event Abstract ### post_event_abstract_obj() ###
# Updated 2023-03-20
@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
inc_event_presentation_list: bool = False,
inc_event_presenter_list: bool = False,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# 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_id = event_abstract_obj.event_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.')
if isinstance(create_event_abstract_obj_result, int):
event_abstract_id = create_event_abstract_obj_result
if return_obj:
if load_event_abstract_obj_result := load_event_abstract_obj(
event_abstract_id = event_abstract_id,
inc_event_presentation_list = inc_event_presentation_list,
inc_event_presenter_list = inc_event_presenter_list,
):
data = load_event_abstract_obj_result
else:
data = False
else:
event_abstract_id = event_abstract_id
event_abstract_id_random = get_id_random(record_id=event_abstract_id, table_name='event_abstract')
data = {}
data['event_abstract_id'] = event_abstract_id
data['event_abstract_id_random'] = event_abstract_id_random
return mk_resp(data=data, response=commons.response, status_message='The event abstract was created.')
else:
return mk_resp(data=False, status_code=400, response=commons.response, status_message='The result from trying to create an event abstract was unexpected.')
# ### END ### API Event Abstract ### post_event_abstract_obj() ###
# ### BEGIN ### API Event Abstract ### patch_event_abstract_obj() ###
# Updated 2023-03-20
@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_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
inc_event_presentation_list: bool = False,
inc_event_presenter_list: bool = False,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
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)
if update_event_abstract_obj_result := create_update_event_abstract_obj(
event_abstract_dict_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,
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.')
if update_event_abstract_obj_result:
if return_obj:
if load_event_abstract_obj_result := load_event_abstract_obj(
event_abstract_id = event_abstract_id,
inc_event_presentation_list = inc_event_presentation_list,
inc_event_presenter_list = inc_event_presenter_list,
):
data = load_event_abstract_obj_result
else:
data = False
else:
event_abstract_id_random = get_id_random(record_id=event_abstract_id, table_name='event_abstract')
data = {}
data['event_abstract_id'] = event_abstract_id
data['event_abstract_id_random'] = event_abstract_id_random
return mk_resp(data=data, response=commons.response, status_message='The event abstract was created or updated.')
else:
return mk_resp(data=False, status_code=400, response=commons.response, status_message='The result from trying to create an event abstract was unexpected.')
# ### END ### API Event Abstract ### patch_event_abstract_obj() ###
# ### BEGIN ### API Event Abstract ### get_event_abstract_obj() ###
# Updated 2023-03-20
@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_person: bool = False,
# inc_event_person_profile: bool = False,
inc_event_presentation_list: bool = False,
inc_event_presenter_list: bool = False,
approved: str = 'all', # approved, not_approved, all
hidden: str = 'not_hidden', # hidden, not_hidden, all
review: str = 'all', # hidden, not_hidden, all
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# time.sleep(.5)
# ### SECTION ### Secondary data validation
event_abstract_id_random = event_abstract_id # This is used later for the response data
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, status_message='The Event Abstract ID was invalid or not found.')
if event_abstract_obj_result := load_event_abstract_obj(
event_abstract_id = event_abstract_id,
enabled = commons.enabled,
approved = approved, # approved, not_approved, all
hidden = hidden, # hidden, not_hidden, all
review = review, # ready, not_ready, all
inc_event_person = inc_event_person,
inc_event_presentation_list = inc_event_presentation_list,
inc_event_presenter_list = inc_event_presenter_list,
):
log.info('Loading successful. Returning 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')
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
else:
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() ###

View File

@@ -340,7 +340,7 @@ async def get_person_obj(
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# ### SECTION ### Secondary data validation