import datetime, time 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_enable_part, sql_insert, sql_update, sql_insert_or_update, sql_limit_offset_part, sql_select, sql_delete, redis_lookup_id_random from .api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template from app.methods.event_exhibit_methods import load_event_exhibit_obj from app.models.event_exhibit_models import Event_Exhibit_Base from app.models.response_models import Resp_Body_Base, mk_resp router = APIRouter() @router.post('/event/exhibit', response_model=Resp_Body_Base) async def post_event_exhibit_obj( obj: Event_Exhibit_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_exhibit' 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('/event/exhibit/{obj_id}', response_model=Resp_Body_Base) async def patch_event_exhibit_obj( obj_id: str = Query(..., min_length=1, max_length=22), obj: Event_Exhibit_Base = None, 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_exhibit' 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 @router.get('/event/exhibit/list', response_model=Resp_Body_Base) async def get_event_exhibit_obj_li( for_obj_type: Optional[str] = Query(None, min_length=2, max_length=50), for_obj_id: Optional[str] = Query(None, min_length=1, max_length=22), x_account_id: str = Header(...), 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_exhibit' result = get_obj_li_template( obj_type=obj_type, for_obj_type=for_obj_type, for_obj_id=for_obj_id, by_alias=True, exclude_unset=True, ) return result # ### BEGIN ### API Event Exhibit ### get_event_exhibit_obj() ### # Updated 2022-02-15 @router.get('/event/exhibit/{event_exhibit_id}', response_model=Resp_Body_Base) async def get_event_exhibit_obj( event_exhibit_id: str = Query(..., min_length=11, max_length=22), inc_event_exhibit_tracking_list: bool = False, inc_event_badge: bool = False, inc_event_person: bool = False, # inc_event_person_profile: bool = False, commons: Common_Route_Params = Depends(common_route_params), ): log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) # time.sleep(1) # ### SECTION ### Secondary data validation event_exhibit_id_random = event_exhibit_id # This is used later for the response data if event_exhibit_id := redis_lookup_id_random(record_id_random=event_exhibit_id, table_name='event_exhibit'): pass else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The Event Exhibit ID was invalid or not found.') if event_exhibit_obj_result := load_event_exhibit_obj( event_exhibit_id = event_exhibit_id, inc_event_exhibit_tracking_list = inc_event_exhibit_tracking_list, inc_event_badge = inc_event_badge, inc_event_person = inc_event_person, # inc_event_person_profile = inc_event_person_profile, ): log.info('Loading successful. Returning result') return mk_resp(data=event_exhibit_obj_result, response=commons.response) # Success elif isinstance(event_exhibit_obj_result, list) or event_exhibit_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 Exhibit ### get_event_exhibit_obj() ### @router.delete('/event/exhibit/{obj_id}', response_model=Resp_Body_Base) async def delete_event_exhibit_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_exhibit' result = delete_obj_template( obj_type=obj_type, obj_id=obj_id, ) return result