Updated event location related. General code clean up and updates.

This commit is contained in:
Scott Idem
2022-09-23 16:27:46 -04:00
parent f691137a78
commit 97bd91f006
3 changed files with 90 additions and 29 deletions

View File

@@ -38,7 +38,7 @@ logging.config.dictConfig({
} }
}, },
'root': { 'root': {
'handlers': ['console', 'log_file_all'], #, 'log_file_all', 'log_file_warning'], 'handlers': ['console'], #, 'log_file_all', 'log_file_warning'],
'level': 'WARNING', # WARNING 'level': 'WARNING', # WARNING
} }
}) })

View File

@@ -29,6 +29,7 @@ class Event_Location_Base(BaseModel):
event_id_random: Optional[str] event_id_random: Optional[str]
event_id: Optional[int] event_id: Optional[int]
event_track_id_random: Optional[str] # Can a track be assigned to one location? event_track_id_random: Optional[str] # Can a track be assigned to one location?
event_track_id: Optional[int] # Can a track be assigned to one location? event_track_id: Optional[int] # Can a track be assigned to one location?
@@ -88,41 +89,25 @@ class Event_Location_Base(BaseModel):
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now) _processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
#@validator('event_location_id_random', always=True)
def event_location_id_random_copy(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values['id_random']:
return values['id_random']
return None
@validator('id', always=True) @validator('id', always=True)
def event_location_id_lookup(cls, v, values, **kwargs): def event_location_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING) if isinstance(v, int) and v > 0: return v
log.debug(locals()) elif id_random := values.get('id_random'):
return redis_lookup_id_random(record_id_random=id_random, table_name='event_location')
if values['id_random']:
log.debug(values['id_random'])
return redis_lookup_id_random(record_id_random=values['id_random'], table_name='event_location')
return None return None
@validator('event_id', always=True) @validator('event_id', always=True)
def event_id_lookup(cls, v, values, **kwargs): def event_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING) if isinstance(v, int) and v > 0: return v
log.debug(locals()) elif id_random := values.get('event_id_random'):
return redis_lookup_id_random(record_id_random=id_random, table_name='event')
if values['event_id_random']:
return redis_lookup_id_random(record_id_random=values['event_id_random'], table_name='event')
return None return None
@validator('event_track_id', always=True) @validator('event_track_id', always=True)
def event_track_id_lookup(cls, v, values, **kwargs): def event_track_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING) if isinstance(v, int) and v > 0: return v
log.debug(locals()) elif id_random := values.get('event_track_id_random'):
return redis_lookup_id_random(record_id_random=id_random, table_name='event_track')
if values['event_track_id_random']:
return redis_lookup_id_random(record_id_random=values['event_track_id_random'], table_name='event_track')
return None return None
class Config: class Config:

View File

@@ -1,9 +1,8 @@
import datetime
from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, Response, status from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, Response, status
from pydantic import BaseModel, EmailStr, Field from pydantic import BaseModel, EmailStr, Field
from typing import Dict, List, Optional, Set, Union from typing import Dict, List, Optional, Set, Union
from app.lib_general import log, logging from app.lib_general import log, logging, common_route_params, Common_Route_Params
from app.config import settings 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.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, redis_lookup_id_random
@@ -18,6 +17,64 @@ from app.models.response_models import Resp_Body_Base, mk_resp
router = APIRouter() router = APIRouter()
# ### BEGIN ### API Event Location ### post_event_location_obj_new_v4() ###
# Updated 2022-09-23
@router.post('/event/location/new_v4', response_model=Resp_Body_Base)
async def post_event_location_obj_new_v4(
event_location_obj: Event_Location_Base,
create_sub_obj: bool = False,
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
inc_event_file_list: bool = False,
inc_event_session_list: bool = False,
return_obj: bool = True,
commons: Common_Route_Params = Depends(common_route_params),
# x_account_id: str = Header(...),
# limit: int = 500,
# enabled: str = 'enabled',
# by_alias: bool = True,
# exclude_unset: bool = True,
# response: Response = Response,
):
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_location_obj_result := create_update_event_location_obj_v4(
event_location_dict_obj = event_location_obj,
event_id = event_location_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 location was not created. Check the field names and data types.')
if isinstance(create_event_location_obj_result, int):
event_location_id = create_event_location_obj_result
if return_obj:
if load_event_location_obj_result := load_event_location_obj(
event_location_id = event_location_id,
inc_event_file_list = inc_event_file_list,
inc_event_session_list = inc_event_session_list,
):
data = load_event_location_obj_result
else:
data = False
else:
event_location_id = event_location_id
event_location_id_random = get_id_random(record_id=event_location_id, table_name='event_location')
data = {}
data['event_location_id'] = event_location_id
data['event_location_id_random'] = event_location_id_random
return mk_resp(data=data, response=commons.response, status_message='The event location was created.')
else:
return mk_resp(data=False, status_code=400, response=commons.response, status_message='The result from trying to create an event location was unexpected.')
# ### END ### API Event Location ### post_event_location_obj_new_v4() ###
# ### BEGIN ### API Event Location ### patch_event_location_obj_exist_v4() ### # ### BEGIN ### API Event Location ### patch_event_location_obj_exist_v4() ###
# Updated 2021-10-22 # Updated 2021-10-22
@router.patch('/event/location/{event_location_id}/exist_v4', response_model=Resp_Body_Base) @router.patch('/event/location/{event_location_id}/exist_v4', response_model=Resp_Body_Base)
@@ -39,7 +96,7 @@ async def patch_event_location_obj_exist_v4(
exclude_none: Optional[bool] = True, exclude_none: Optional[bool] = True,
response: Response = Response, response: Response = Response,
): ):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
if event_location_id := redis_lookup_id_random(record_id_random=event_location_id, table_name='event_location'): pass if event_location_id := redis_lookup_id_random(record_id_random=event_location_id, table_name='event_location'): pass
@@ -179,3 +236,22 @@ async def get_event_obj_event_location_list(
return mk_resp(data=response_data, response=response) return mk_resp(data=response_data, response=response)
# ### END ### API Event Location ### get_event_obj_event_location_list() ### # ### END ### API Event Location ### get_event_obj_event_location_list() ###
# ### BEGIN ### API Event Location ### delete_event_location_obj() ###
# Updated 2022-09-23
@router.delete('/event/location/{obj_id}', response_model=Resp_Body_Base)
async def delete_event_location_obj(
obj_id: str = Query(..., min_length=11, max_length=22),
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
obj_type = 'event_location'
result = delete_obj_template(
obj_type=obj_type,
obj_id=obj_id,
)
return result
# ### END ### API Event Location ### delete_event_location_obj() ###