Work on person methods and related and event badge everything

This commit is contained in:
Scott Idem
2021-09-08 15:58:35 -04:00
parent d0d8392817
commit 54a43cc124
12 changed files with 1071 additions and 417 deletions

View File

@@ -11,7 +11,7 @@ from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_
# from app.methods.membership_person_methods import load_membership_person_obj
from app.methods.order_methods import get_order_rec_list, load_order_obj
from app.methods.person_methods import create_person_obj_v3, create_update_person_obj, get_person_rec_list, get_person_rec_w_external_id, load_person_obj, update_person_obj, update_person_obj_v3
from app.methods.person_methods import create_update_person_obj_v4b, get_person_rec_list, get_person_rec_w_external_id, load_person_obj, update_person_obj
from app.models.person_models import Person_Base
from app.models.response_models import Resp_Body_Base, mk_resp
@@ -73,121 +73,148 @@ async def patch_person_obj(
# ### BEGIN ### API Person ### v3_post_person_obj_new() ###
# Updated 2021-08-24
# Using create_update_person_obj_v4b() now
# Updated 2021-09-08
@router.post('/v3/person/new', response_model=Resp_Body_Base)
async def v3_post_person_obj_new(
person_obj: Person_Base,
process_contact: bool = False,
process_organization: bool = False,
process_user: bool = False,
create_sub_obj: bool = False,
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
enabled: str = 'enabled', # For now this covers any included objects or object lists
inc_address: bool = False, # Priority l1
inc_contact: bool = False, # Priority l1
inc_user: bool = False, # Priority l1
x_account_id: str = Header(...),
inc_address: bool = False,
inc_contact: bool = False,
inc_organization: bool = False,
inc_user: bool = False,
return_obj: bool = True,
limit: int = 50,
by_alias: bool = True,
exclude_unset: bool = True,
# include: Optional[list] = [],
# exclude: Optional[list] = [],
exclude_unset: Optional[bool] = True,
# exclude_none: Optional[bool] = True,
x_account_id: str = Header(...),
response: Response = Response,
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
log.debug(person_obj.account_id)
log.debug(person_obj.account_id_random)
# if person_obj.account_id: pass
# else: return mk_resp(data=False, status_code=500, response=response, status_message='Testing')
# abort(501)
# There should probably be a check for the account ID before calling the create function?
if create_person_obj_result := create_person_obj_v3(
if create_update_person_obj_result := create_update_person_obj_v4b(
account_id = x_account_id,
person_obj_new = person_obj,
create_sub_obj = create_sub_obj,
fail_any = fail_any,
return_outline = False,
person_dict_obj = person_obj,
person_id = None,
# process_contact = process_contact,
# process_organization = process_organization,
# process_user = process_user,
): pass
else: return mk_resp(data=False, status_code=400, response=response, status_message='The person was not created. Check the field names and data types.')
if isinstance(create_person_obj_result, int):
person_id = create_person_obj_result
if isinstance(create_update_person_obj_result, int):
person_id = create_update_person_obj_result
if return_obj:
if load_person_obj_result := load_person_obj(
person_id = person_id,
enabled = enabled,
inc_address = inc_address,
inc_contact = inc_contact,
inc_organization = inc_organization,
inc_user = inc_user,
):
data = load_person_obj_result
else:
data = False
return mk_resp(data=data, response=response, status_message='The person was probably created, but there was a problem returning the data.')
else:
person_id = create_person_obj_result
person_id = create_update_person_obj_result
person_id_random = get_id_random(record_id=person_id, table_name='person')
data = {}
data['person_id'] = person_id
data['person_id_random'] = person_id_random
return mk_resp(data=data, response=response, status_message='The person was created.')
else:
return mk_resp(data=False, status_code=400, response=response, status_message='The result from trying to create an person was unexpected.')
return mk_resp(data=False, status_code=400, response=response, status_message='The result from trying to create a person was unexpected.')
# ### BEGIN ### API Person ### v3_post_person_obj_new() ###
# ### BEGIN ### API Person ### v3_patch_person_obj_exist ###
# Updated 2021-08-24
# Using create_update_person_obj_v4b() now
# Updated 2021-09-08
@router.patch('/v3/person/{person_id}/exist', response_model=Resp_Body_Base)
async def v3_patch_person_obj_exist(
person_obj: Person_Base,
person_id: str = Query(..., min_length=11, max_length=22),
process_contact: bool = False,
process_organization: bool = False,
process_user: bool = False,
create_sub_obj: bool = False,
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True,
enabled: str = 'enabled', # For now this covers any included objects or object lists
inc_address: bool = False,
inc_contact: bool = False,
inc_organization: bool = False,
inc_user: bool = False,
return_obj: bool = True,
limit: int = 50,
by_alias: bool = True,
# include: Optional[list] = [],
# exclude: Optional[list] = [],
exclude_unset: Optional[bool] = True,
exclude_none: Optional[bool] = True,
# exclude_none: Optional[bool] = True,
x_account_id: str = Header(...),
response: Response = Response,
):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
else: return mk_resp(data=None, status_code=404)
else: return mk_resp(data=None, status_code=404, response=response, status_message='The person was not updated. The person ID was invalid or not found.')
if update_person_obj_result := update_person_obj_v3(
if create_update_person_obj_result := create_update_person_obj_v4b(
account_id = x_account_id,
person_dict_obj = person_obj,
person_id = person_id,
person_obj_exist = person_obj,
create_sub_obj = create_sub_obj,
fail_any = fail_any,
return_outline = False,
# process_contact = process_contact,
# process_organization = process_organization,
# process_user = process_user,
): pass
else: return mk_resp(data=False, status_code=400, response=response, status_message='The person was not created. Check the field names and data types.')
else: return mk_resp(data=False, status_code=400, response=response, status_message='The person was not updated. Check the field names and data types.')
if update_person_obj_result:
if isinstance(create_update_person_obj_result, int):
person_id = create_update_person_obj_result
if return_obj:
if load_person_obj_result := load_person_obj(person_id=person_id):
if load_person_obj_result := load_person_obj(
person_id = person_id,
enabled = enabled,
inc_address = inc_address,
inc_contact = inc_contact,
inc_organization = inc_organization,
inc_user = inc_user,
):
data = load_person_obj_result
else:
data = False
return mk_resp(data=data, response=response, status_message='The person was probably updated, but there was a problem returning the data.')
else:
person_id = create_update_person_obj_result
person_id_random = get_id_random(record_id=person_id, table_name='person')
data = {}
data['person_id'] = person_id
data['person_id_random'] = person_id_random
return mk_resp(data=data, response=response, status_message='The person was created.')
return mk_resp(data=data, response=response, status_message='The person was updated.')
else:
return mk_resp(data=False, status_code=400, response=response, status_message='The result from trying to create an person was unexpected.')
return mk_resp(data=False, status_code=400, response=response, status_message='The result from trying to update the person was unexpected.')
# ### END ### API Person ### v3_patch_person_obj_exist ###
# ### BEGIN ### API Person ### post_person_json() ###
# Updated 2021-06-25
# Updated 2021-09-08
@router.post('/person/json', response_model=Resp_Body_Base)
async def post_person_json(
person_obj: Person_Base,
@@ -195,26 +222,26 @@ async def post_person_json(
# create_sub_obj: bool = False,
process_contact: bool = False,
process_organization: bool = False,
x_account_id: Optional[str] = Header(..., ),
process_user: bool = False,
return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True,
include: Optional[list] = [],
exclude: Optional[list] = [],
# include: Optional[list] = [],
# exclude: Optional[list] = [],
exclude_unset: Optional[bool] = True,
exclude_none: Optional[bool] = True,
# exclude_none: Optional[bool] = True,
x_account_id: Optional[str] = Header(..., ),
response: Response = Response,
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
# else: return mk_resp(data=None, status_code=404)
if person_obj_in_result := create_update_person_obj(
if person_obj_in_result := create_update_person_obj_v4b(
account_id = x_account_id,
person_dict_obj = person_obj,
person_id = None,
person_obj = person_obj,
process_contact = process_contact,
process_organization = process_organization,
process_user = process_user,
):
log.debug(person_obj_in_result)
if return_obj:
@@ -233,9 +260,10 @@ async def post_person_json(
@router.patch('/person/{person_id}/json', response_model=Resp_Body_Base)
async def patch_person_json(
person_obj: Person_Base,
person_id: str = Query(..., min_length=1, max_length=22),
person_id: str = Query(..., min_length=11, max_length=22),
process_contact: bool = False,
process_organization: bool = False,
process_user: bool = False,
x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True,
@@ -251,11 +279,12 @@ async def patch_person_json(
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
else: return mk_resp(data=None, status_code=404, response=response)
if person_obj_up_result := create_update_person_obj(
person_id = person_id,
person_obj = person_obj,
if person_obj_up_result := create_update_person_obj_v4b(
account_id = x_account_id,
person_dict_obj = person_obj,
process_contact = process_contact,
process_organization = process_organization,
process_user = process_user,
):
log.debug(person_obj_up_result)
if return_obj: