Work on fancy API CRUD
This commit is contained in:
@@ -47,8 +47,8 @@ class Event_Session_Base(BaseModel):
|
|||||||
poc_event_person_id_random: Optional[str]
|
poc_event_person_id_random: Optional[str]
|
||||||
poc_event_person_id: Optional[int]
|
poc_event_person_id: Optional[int]
|
||||||
|
|
||||||
poc_person_id_random: Optional[str] # Not used or needed?
|
# poc_person_id_random: Optional[str] # Not used or needed?
|
||||||
poc_person_id: Optional[int] # Not used or needed?
|
# poc_person_id: Optional[int] # Not used or needed?
|
||||||
|
|
||||||
# type_id_random: Optional[str] # Not used or needed?
|
# type_id_random: Optional[str] # Not used or needed?
|
||||||
# type_id: Optional[int] # Not used or needed?
|
# type_id: Optional[int] # Not used or needed?
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ obj_type_li['event_person_tracking'] = {'table_name': 'v_event_person_tracking',
|
|||||||
obj_type_li['event_presentation'] = {'table_name': 'v_event_presentation', 'tbl_name_update': 'event_presentation', 'base_name': Event_Presentation_Base}
|
obj_type_li['event_presentation'] = {'table_name': 'v_event_presentation', 'tbl_name_update': 'event_presentation', 'base_name': Event_Presentation_Base}
|
||||||
obj_type_li['event_presenter'] = {'table_name': 'v_event_presenter', 'tbl_name_update': 'event_presenter', 'base_name': Event_Presenter_Base}
|
obj_type_li['event_presenter'] = {'table_name': 'v_event_presenter', 'tbl_name_update': 'event_presenter', 'base_name': Event_Presenter_Base}
|
||||||
obj_type_li['event_registration'] = {'table_name': 'v_event_registration', 'tbl_name_update': 'event_registration', 'base_name': Event_Registration_Base}
|
obj_type_li['event_registration'] = {'table_name': 'v_event_registration', 'tbl_name_update': 'event_registration', 'base_name': Event_Registration_Base}
|
||||||
obj_type_li['event_session'] = {'table_name': 'v_event_session', 'tbl_name_update': 'event_session', 'base_name': Event_Session_Base}
|
obj_type_li['event_session'] = {'table_name': 'v_event_session', 'tbl_name_update': 'event_session', 'base_name': Event_Session_Base, 'exclude_for_db': {'poc_person_id', 'file_count', 'internal_use_count', 'enable_from', 'enable_to', 'event_name', 'event_start_datetime', 'event_end_datetime', 'event_location_name', 'event_track_name', 'event_abstract_list', 'event_badge_list', 'event_device_list', 'event_file_list', 'event_file_internal_use_list', 'event_location', 'event_location_list', 'event_person_list', 'event_presenter_cat', 'event_presentation_list', 'event_presenter_list', 'event_track', 'poc_event_person'}}
|
||||||
obj_type_li['event_track'] = {'table_name': 'v_event_track', 'tbl_name_update': 'event_track', 'base_name': Event_Track_Base}
|
obj_type_li['event_track'] = {'table_name': 'v_event_track', 'tbl_name_update': 'event_track', 'base_name': Event_Track_Base}
|
||||||
obj_type_li['hosted_file'] = {'table_name': 'v_hosted_file', 'tbl_name_update': 'hosted_file', 'base_name': Hosted_File_Base}
|
obj_type_li['hosted_file'] = {'table_name': 'v_hosted_file', 'tbl_name_update': 'hosted_file', 'base_name': Hosted_File_Base}
|
||||||
#obj_type_li['hosted_file_link'] = {'table_name': 'hosted_file_link', 'tbl_name_update': 'hosted_file_link', 'base_name': Hosted_File_Link_Base}
|
#obj_type_li['hosted_file_link'] = {'table_name': 'hosted_file_link', 'tbl_name_update': 'hosted_file_link', 'base_name': Hosted_File_Link_Base}
|
||||||
@@ -360,10 +360,14 @@ async def patch_obj(
|
|||||||
- /order/cart/line = order_cart_line
|
- /order/cart/line = order_cart_line
|
||||||
- /lu/some_lookup = lu_some_lookup
|
- /lu/some_lookup = lu_some_lookup
|
||||||
"""
|
"""
|
||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
if crud.super_key == '789123': pass
|
if crud.super_key == 'zp5PtX4zUsI': pass
|
||||||
|
elif crud.jwt:
|
||||||
|
# pass
|
||||||
|
log.warning('JWT was passed')
|
||||||
|
return mk_resp(data=False, status_code=501, response=commons.response, status_message='Token access for the API CRUD has not been implemented yet.')
|
||||||
else:
|
else:
|
||||||
log.warning('Access key is missing or incorrect')
|
log.warning('Access key is missing or incorrect')
|
||||||
return mk_resp(data=False, status_code=400, response=commons.response)
|
return mk_resp(data=False, status_code=400, response=commons.response)
|
||||||
@@ -416,6 +420,7 @@ async def patch_obj(
|
|||||||
return mk_resp(data=False, status_code=400, response=commons.response)
|
return mk_resp(data=False, status_code=400, response=commons.response)
|
||||||
|
|
||||||
table_name = obj_type_li[obj_name]['tbl_name_update']
|
table_name = obj_type_li[obj_name]['tbl_name_update']
|
||||||
|
exclude = obj_type_li[obj_name]['exclude_for_db']
|
||||||
|
|
||||||
# ### SECTION ### Secondary data validation
|
# ### SECTION ### Secondary data validation
|
||||||
# obj_id_random = obj_id # This might need to be used later for the response data
|
# obj_id_random = obj_id # This might need to be used later for the response data
|
||||||
@@ -424,19 +429,24 @@ async def patch_obj(
|
|||||||
|
|
||||||
# NOTE: Doing a quick sanity check based on the object models and then dump to a dict to get rid of invalid fields. The other option is to just use the crud.data_list raw.
|
# NOTE: Doing a quick sanity check based on the object models and then dump to a dict to get rid of invalid fields. The other option is to just use the crud.data_list raw.
|
||||||
crud_data = crud.data_list
|
crud_data = crud.data_list
|
||||||
|
log.debug(crud_data.keys())
|
||||||
|
field_list = crud_data.keys()
|
||||||
|
|
||||||
if run_safety_check:
|
if run_safety_check:
|
||||||
log.info('Running safety check by default')
|
log.info('Running safety check by default')
|
||||||
base_name = obj_type_li[obj_name]['base_name']
|
base_name = obj_type_li[obj_name]['base_name']
|
||||||
obj_model = base_name(**crud.data_list) # .dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
obj_model = base_name(**crud.data_list) # .dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||||
log.debug(obj_model)
|
log.debug(obj_model)
|
||||||
obj_dict = obj_model.dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
# obj_dict = obj_model.dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset, exclude=exclude)
|
||||||
|
obj_dict = obj_model.dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset, include=field_list)
|
||||||
log.debug(obj_dict)
|
log.debug(obj_dict)
|
||||||
crud_data = obj_dict
|
crud_data = obj_dict
|
||||||
else:
|
else:
|
||||||
log.warning('The default safety check was not run!')
|
log.warning('The default safety check was not run!')
|
||||||
|
obj_dict = crud_data
|
||||||
|
|
||||||
# NOTE: Add a check for the object ID... assuming it is a random ID string for now.
|
# NOTE: Add a check for the object ID... assuming it is a random ID string for now. Using rm_id_random. That helps with some field names.
|
||||||
if sql_result := sql_update(data=crud_data, table_name=table_name, record_id=obj_id, log_lvl=logging.INFO):
|
if sql_result := sql_update(data=crud_data, table_name=table_name, record_id=obj_id, rm_id_random=True, log_lvl=logging.INFO):
|
||||||
log.info('The record was updated.')
|
log.info('The record was updated.')
|
||||||
log.debug(sql_result)
|
log.debug(sql_result)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user