225 lines
11 KiB
Python
225 lines
11 KiB
Python
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, remove_event_abstract_obj
|
|
|
|
from app.models.event_abstract_models import Event_Abstract_In
|
|
from app.models.response_models import Resp_Body_Base, mk_resp
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
# ### BEGIN ### API Event Abstract ### post_event_abstract_obj() ###
|
|
# Updated 2023-03-22
|
|
@router.post('/event/abstract', response_model=Resp_Body_Base)
|
|
async def post_event_abstract_obj(
|
|
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,
|
|
|
|
commons: Common_Route_Params = Depends(common_route_params),
|
|
):
|
|
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_obj = event_abstract_obj,
|
|
event_id = event_abstract_obj.event_id,
|
|
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.')
|
|
|
|
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_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,
|
|
):
|
|
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-22
|
|
@router.patch('/event/abstract/{event_abstract_id}', response_model=Resp_Body_Base)
|
|
async def patch_event_abstract_obj(
|
|
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
|
|
|
|
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,
|
|
|
|
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, status_message='The Event Abstract ID was invalid or not found.')
|
|
|
|
if update_event_abstract_obj_result := create_update_event_abstract_obj(
|
|
event_abstract_obj = event_abstract_obj,
|
|
event_abstract_id = event_abstract_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_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,
|
|
):
|
|
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-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 = True,
|
|
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.DEBUG) # 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_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')
|
|
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() ###
|
|
|
|
|
|
# ### 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() ### |