Working on all module routes, methods, and models
This commit is contained in:
@@ -9,8 +9,9 @@ from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select,
|
||||
|
||||
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.account_methods import load_account_obj
|
||||
from app.methods.account_methods import load_account_obj, load_account_obj_membership_type
|
||||
from app.methods.account_cfg_methods import load_account_cfg_obj
|
||||
from app.methods.membership_group_methods import get_membership_group_rec_list, load_membership_group_obj
|
||||
|
||||
from app.models.account_models import Account_Base
|
||||
from app.models.response_models import Resp_Body_Base, mk_resp
|
||||
@@ -272,9 +273,30 @@ async def get_account_obj_new(
|
||||
# ### END ### API Account ### get_account_obj_new() ###
|
||||
|
||||
|
||||
@router.get('/{obj_id}', response_model=Resp_Body_Base)
|
||||
async def get_account_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
# ### BEGIN ### API Account ### get_account_obj_membership() ###
|
||||
# Working well as of 2021-06-23. Using as a template for other routes.
|
||||
@router.get('/{account_id}/membership', response_model=Resp_Body_Base)
|
||||
async def get_account_obj_membership(
|
||||
account_id: str = Query(..., min_length=1, max_length=22),
|
||||
limit: int = 500, # For now this covers any included objects or object lists
|
||||
enabled: str = 'enabled', # For now this covers any included objects or object lists
|
||||
inc_account_cfg: bool = False,
|
||||
inc_address: bool = False, # Under contact
|
||||
inc_contact: bool = False,
|
||||
inc_membership_cfg: bool = False,
|
||||
inc_membership_group: bool = False,
|
||||
inc_membership_group_list: bool = False,
|
||||
inc_membership_member: bool = False,
|
||||
inc_membership_member_list: bool = False,
|
||||
inc_membership_member_profile: bool = False,
|
||||
inc_membership_type: bool = False,
|
||||
inc_membership_type_list: bool = False,
|
||||
inc_order: bool = False,
|
||||
inc_organization: bool = False,
|
||||
inc_person: bool = False,
|
||||
inc_product: bool = False,
|
||||
inc_product_list: bool = False,
|
||||
inc_user: bool = False,
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
@@ -282,14 +304,161 @@ async def get_account_obj(
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
obj_type = 'account'
|
||||
result = get_obj_template(
|
||||
obj_type=obj_type,
|
||||
obj_id=obj_id,
|
||||
by_alias=True,
|
||||
exclude_unset=True,
|
||||
)
|
||||
return result
|
||||
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||
else:
|
||||
return mk_resp(data=None, status_code=404)
|
||||
|
||||
if account_result := load_account_obj_membership_type(
|
||||
account_id = account_id,
|
||||
enabled = enabled,
|
||||
limit = limit,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
model_as_dict = False, # NOTE: returning model as a dict
|
||||
inc_account_cfg = inc_account_cfg,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_membership_cfg = inc_membership_cfg,
|
||||
inc_membership_group_list = inc_membership_group_list,
|
||||
inc_membership_member = inc_membership_member,
|
||||
inc_membership_member_list = inc_membership_member_list,
|
||||
inc_membership_member_profile = inc_membership_member_profile,
|
||||
inc_membership_type_list = inc_membership_type_list,
|
||||
# inc_order = inc_order,
|
||||
# inc_order_list = inc_order_list,
|
||||
inc_organization = inc_organization,
|
||||
inc_person = inc_person,
|
||||
inc_product = inc_product,
|
||||
inc_product_list = inc_product_list,
|
||||
inc_user = inc_user,
|
||||
):
|
||||
if isinstance(account_result, dict):
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.info('Result is a dict')
|
||||
response_data = account_result
|
||||
log.debug(response_data)
|
||||
else:
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.info('Result is probably an object model')
|
||||
response_data = account_result
|
||||
log.debug(response_data)
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data)
|
||||
# ### END ### API Account ### get_account_obj_membership() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Account ### get_account_obj_membership() ###
|
||||
# Working well as of 2021-06-23. Using as a template for other routes.
|
||||
@router.get('/{account_id}/membership_group_list', response_model=Resp_Body_Base)
|
||||
async def get_account_obj_membership_group_list(
|
||||
account_id: str = Query(..., min_length=1, max_length=22),
|
||||
limit: int = 500, # For now this covers any included objects or object lists
|
||||
enabled: str = 'enabled', # For now this covers any included objects or object lists
|
||||
inc_account_cfg: bool = False,
|
||||
inc_address: bool = False, # Under contact
|
||||
inc_contact: bool = False,
|
||||
inc_membership_cfg: bool = False,
|
||||
inc_membership_group_member_list: bool = False, # per membership group
|
||||
inc_membership_member: bool = False,
|
||||
inc_membership_member_profile: bool = False,
|
||||
inc_membership_type: bool = False,
|
||||
# inc_membership_type_list: bool = False,
|
||||
# inc_order: bool = False,
|
||||
inc_organization: bool = False,
|
||||
inc_person: bool = False,
|
||||
# inc_product: bool = False,
|
||||
inc_product_list: bool = False,
|
||||
inc_user: bool = False,
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||
else:
|
||||
return mk_resp(data=None, status_code=404)
|
||||
|
||||
response_data = None
|
||||
|
||||
# Updated 2021-06-23
|
||||
if membership_group_rec_list_result := get_membership_group_rec_list(
|
||||
for_obj_type = 'account',
|
||||
for_obj_id = account_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
):
|
||||
membership_group_result_list = []
|
||||
for membership_group_rec in membership_group_rec_list_result:
|
||||
if load_membership_group_result := load_membership_group_obj(
|
||||
membership_group_id = membership_group_rec.get('membership_group_id', None),
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_membership_cfg = inc_membership_cfg,
|
||||
# inc_membership_group_member_list = inc_membership_group_member_list,
|
||||
inc_membership_member = inc_membership_member,
|
||||
inc_membership_member_profile = inc_membership_member_profile,
|
||||
# inc_membership_type_list = inc_membership_type_list,
|
||||
# inc_membership_member_list = inc_membership_member_list,
|
||||
# inc_membership_group_member_list = inc_membership_group_member_list,
|
||||
inc_person = inc_person,
|
||||
inc_product_list = inc_product_list,
|
||||
inc_user = inc_user,
|
||||
):
|
||||
membership_group_result_list.append(load_membership_group_result)
|
||||
else:
|
||||
membership_group_result_list.append(None)
|
||||
response_data = membership_group_result_list
|
||||
|
||||
# if account_result := load_membership_group_list(
|
||||
# account_id = account_id,
|
||||
# enabled = enabled,
|
||||
# limit = limit,
|
||||
# by_alias = by_alias,
|
||||
# exclude_unset = exclude_unset,
|
||||
# model_as_dict = False, # NOTE: returning model as a dict
|
||||
# inc_account_cfg = inc_account_cfg,
|
||||
# inc_address = inc_address,
|
||||
# inc_contact = inc_contact,
|
||||
# inc_membership_cfg = inc_membership_cfg,
|
||||
# inc_membership_group_member_list = inc_membership_group_member_list,
|
||||
# inc_membership_member = inc_membership_member,
|
||||
# inc_membership_member_profile = inc_membership_member_profile,
|
||||
# inc_membership_type = inc_membership_type,
|
||||
# # inc_membership_type_list = inc_membership_type_list,
|
||||
# # inc_order = inc_order,
|
||||
# # inc_order_list = inc_order_list,
|
||||
# inc_organization = inc_organization,
|
||||
# inc_person = inc_person,
|
||||
# # inc_product = inc_product,
|
||||
# inc_product_list = inc_product_list,
|
||||
# inc_user = inc_user,
|
||||
# ):
|
||||
# if isinstance(account_result, dict):
|
||||
# # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.info('Result is a dict')
|
||||
# response_data = account_result
|
||||
# log.debug(response_data)
|
||||
# else:
|
||||
# # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.info('Result is probably an object model')
|
||||
# response_data = account_result
|
||||
# log.debug(response_data)
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data)
|
||||
# ### END ### API Account ### get_account_obj_membership() ###
|
||||
|
||||
|
||||
|
||||
|
||||
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
||||
|
||||
Reference in New Issue
Block a user