188 lines
7.5 KiB
Python
188 lines
7.5 KiB
Python
import datetime
|
|
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
|
|
from app.config import settings
|
|
from app.db_sql import *
|
|
|
|
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_presentation_methods import load_event_presentation_obj
|
|
|
|
from app.models.event_presentation_models import Event_Presentation_Base
|
|
from app.models.response_models import *
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post('', response_model=Resp_Body_Base)
|
|
async def post_event_presentation_obj(
|
|
obj: Event_Presentation_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.debug(locals())
|
|
|
|
obj_type = 'event_presentation'
|
|
obj_data_dict = 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,
|
|
)
|
|
return result
|
|
|
|
|
|
@router.patch('/{obj_id}', response_model=Resp_Body_Base)
|
|
async def patch_event_presentation_obj(
|
|
obj: Event_Presentation_Base,
|
|
obj_id: str = Query(..., min_length=1, max_length=22),
|
|
x_account_id: Optional[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.debug(locals())
|
|
|
|
obj_type = 'event_presentation'
|
|
obj_data_dict = obj.dict(by_alias=False, exclude_unset=True)
|
|
obj_data_dict['id'] = redis_lookup_id_random(record_id_random=obj_id, table_name=obj_type)
|
|
obj_data_dict['id_random'] = obj_id
|
|
result = patch_obj_template(
|
|
obj_type=obj_type,
|
|
data=obj_data_dict,
|
|
obj_id=obj_id,
|
|
return_obj=True,
|
|
by_alias=True,
|
|
exclude_unset=True,
|
|
)
|
|
return result
|
|
|
|
|
|
# ### BEGIN ### API Event Presentation ### patch_event_presentation_json() ###
|
|
@router.patch('/{event_presentation_id}/json', response_model=Resp_Body_Base)
|
|
async def patch_event_presentation_json(
|
|
event_presentation_obj: Event_Presentation_Base,
|
|
event_presentation_id: str = Query(..., min_length=1, max_length=22),
|
|
create_sub_obj: bool = False,
|
|
x_account_id: Optional[str] = Header(..., ),
|
|
return_obj: Optional[bool] = True,
|
|
by_alias: Optional[bool] = True,
|
|
include: Optional[list] = [],
|
|
exclude: Optional[list] = [],
|
|
exclude_unset: Optional[bool] = True,
|
|
exclude_none: Optional[bool] = True,
|
|
response: Response = Response,
|
|
):
|
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
if event_presentation_id := redis_lookup_id_random(record_id_random=event_presentation_id, table_name='event_presentation'): pass
|
|
else:
|
|
return mk_resp(data=None, status_code=404)
|
|
|
|
if event_presentation_obj_up_result := update_event_presentation_obj(
|
|
event_presentation_id=event_presentation_id,
|
|
event_presentation_obj_up=event_presentation_obj,
|
|
create_sub_obj=create_sub_obj,
|
|
):
|
|
|
|
log.debug(event_presentation_obj_up_result)
|
|
if return_obj:
|
|
event_presentation_obj = load_event_presentation_obj(event_presentation_id=event_presentation_id)
|
|
event_presentation_dict = event_presentation_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
|
return mk_resp(data=event_presentation_dict)
|
|
else:
|
|
return mk_resp(data=event_presentation_obj_up_result)
|
|
else:
|
|
return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
|
# ### END ### API Event Presentation ### patch_event_presentation_json() ###
|
|
|
|
|
|
# ### BEGIN ### API Event Presentation ### get_event_presentation_obj() ###
|
|
# Working well as of 2021-06-07. Using as a template for other routes.
|
|
@router.get('/{event_presentation_id}', response_model=Resp_Body_Base)
|
|
async def get_event_presentation_obj(
|
|
event_presentation_id: str = Query(..., min_length=1, max_length=22),
|
|
enabled: str = 'enabled', # enabled, disabled, all; For now this covers any included objects or object lists
|
|
limit: int = 500, # For now this covers any included objects or object lists
|
|
inc_address: bool = False, # Under contact
|
|
inc_contact: bool = False, # Under person
|
|
inc_event_abstract_list: bool = False,
|
|
inc_event_badge: bool = False,
|
|
inc_event_badge_list: bool = False,
|
|
inc_event_device_list: bool = False,
|
|
inc_event_file_list: bool = False,
|
|
inc_event_person_list: bool = False,
|
|
inc_event_presenter_list: bool = False,
|
|
inc_event_registration: bool = False,
|
|
inc_event_registration_list: bool = False,
|
|
# inc_event_session: bool = False, # NOTE: Placehold for future?
|
|
inc_person: bool = False,
|
|
inc_user: bool = False,
|
|
x_account_id: str = Header(...),
|
|
by_alias: Optional[bool] = True,
|
|
exclude_unset: Optional[bool] = True,
|
|
response: Response = Response,
|
|
):
|
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
if event_presentation_id := redis_lookup_id_random(record_id_random=event_presentation_id, table_name='event_presentation'): pass
|
|
else:
|
|
return mk_resp(data=None, status_code=404)
|
|
|
|
if event_presentation_obj := load_event_presentation_obj(
|
|
event_presentation_id = event_presentation_id,
|
|
enabled = enabled,
|
|
limit = limit,
|
|
inc_address = inc_address,
|
|
inc_contact = inc_contact,
|
|
inc_event_abstract_list = inc_event_abstract_list,
|
|
inc_event_badge = inc_event_badge,
|
|
# inc_event_badge_list = inc_event_badge_list,
|
|
inc_event_device_list = inc_event_device_list,
|
|
inc_event_file_list = inc_event_file_list,
|
|
inc_event_person_list = inc_event_person_list,
|
|
inc_event_presenter_list = inc_event_presenter_list,
|
|
inc_event_registration = inc_event_registration,
|
|
# inc_event_registration_list = inc_event_registration_list,
|
|
inc_person = inc_person,
|
|
inc_user = inc_user,
|
|
):
|
|
event_presentation_dict = event_presentation_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
|
pass
|
|
else:
|
|
return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
|
|
|
return mk_resp(data=event_presentation_dict)
|
|
#return mk_resp(data=event_presentation_obj)
|
|
# ### END ### API Event ### get_event_presentation_obj() ###
|
|
|
|
|
|
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
|
async def delete_event_presentation_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 = 'event_presentation'
|
|
result = delete_obj_template(
|
|
obj_type=obj_type,
|
|
obj_id=obj_id,
|
|
)
|
|
return result |