115 lines
4.7 KiB
Python
115 lines
4.7 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 sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, 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_location_methods import get_event_location_rec_list, load_event_location_obj
|
|
|
|
from app.models.event_location_models import Event_Location_Base
|
|
from app.models.response_models import Resp_Body_Base, mk_resp
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API Event Location ### get_event_location_obj() ###
|
|
# Updated 2021-10-09
|
|
@router.get('/event/location/{event_location_id}', response_model=Resp_Body_Base)
|
|
async def get_event_location_obj(
|
|
event_location_id: str = Query(..., min_length=11, max_length=22),
|
|
inc_event_file_list: bool = False,
|
|
inc_event_presentation_list: bool = False,
|
|
inc_event_presenter_list: bool = False,
|
|
inc_event_session_list: bool = False,
|
|
enabled: str = 'enabled', # enabled, disabled, all
|
|
hidden: str = 'not_hidden', # hidden, not_hidden, all
|
|
limit: int = 500,
|
|
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_location_id := redis_lookup_id_random(record_id_random=event_location_id, table_name='event_location'): pass
|
|
else: return mk_resp(data=None, status_code=404, response=response)
|
|
|
|
if event_location_obj := load_event_location_obj(
|
|
event_location_id = event_location_id,
|
|
inc_event_file_list = inc_event_file_list,
|
|
inc_event_presentation_list = inc_event_presentation_list,
|
|
inc_event_presenter_list = inc_event_presenter_list,
|
|
inc_event_session_list = inc_event_session_list,
|
|
enabled = enabled,
|
|
hidden = hidden,
|
|
limit = limit,
|
|
):
|
|
event_location_dict = event_location_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_location_dict, response=response)
|
|
#return mk_resp(data=event_location_obj)
|
|
# ### END ### API Event Location ### get_event_location_obj() ###
|
|
|
|
|
|
|
|
# ### BEGIN ### API Event Location ### get_event_obj_event_location_list() ###
|
|
# Updated 2021-10-09
|
|
@router.get('/event/{event_id}/event/location/list', response_model=Resp_Body_Base)
|
|
async def get_event_obj_event_location_list(
|
|
event_id: str = Query(..., min_length=11, max_length=22),
|
|
enabled: str = 'enabled',
|
|
hidden: str = 'not_hidden',
|
|
limit: int = 500,
|
|
x_account_id: str = Header(...),
|
|
by_alias: Optional[bool] = True,
|
|
exclude_unset: Optional[bool] = True,
|
|
response: Response = Response,
|
|
):
|
|
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=response)
|
|
|
|
response_data = None
|
|
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
|
|
# Updated 2021-07-28
|
|
if event_location_rec_list_result := get_event_location_rec_list(
|
|
event_id = event_id,
|
|
enabled = enabled,
|
|
hidden = hidden,
|
|
limit = limit,
|
|
):
|
|
event_location_result_list = []
|
|
for event_location_rec in event_location_rec_list_result:
|
|
if load_event_location_result := load_event_location_obj(
|
|
event_location_id = event_location_rec.get('event_location_id', None),
|
|
limit = limit,
|
|
by_alias = by_alias,
|
|
exclude_unset = exclude_unset,
|
|
# model_as_dict = model_as_dict,
|
|
enabled = enabled,
|
|
):
|
|
event_location_result_list.append(load_event_location_result)
|
|
else:
|
|
event_location_result_list.append(None)
|
|
response_data = event_location_result_list
|
|
else:
|
|
return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
|
|
|
return mk_resp(data=response_data, response=response)
|
|
# ### END ### API Event Location ### get_event_obj_event_location_list() ###
|