Working on membership, person, user, and order
This commit is contained in:
@@ -9,6 +9,7 @@ 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.order_methods import get_order_rec_list, load_order_obj
|
||||
from app.methods.user_methods import load_user_obj
|
||||
|
||||
from app.models.common_field_schema import default_num_bytes
|
||||
@@ -628,29 +629,65 @@ async def get_user_obj(
|
||||
# ### END ### API User ### get_user_obj() ###
|
||||
|
||||
|
||||
# @router.get('/{user_id}', response_model=Resp_Body_Base)
|
||||
# async def get_user_obj(
|
||||
# user_id: str = Query(..., min_length=1, max_length=22),
|
||||
# x_account_id: str = Header(...),
|
||||
# inc_roles: bool = False,
|
||||
# inc_contact: bool = False,
|
||||
# inc_organization: bool = False,
|
||||
# inc_person: bool = False,
|
||||
# by_alias: bool = True,
|
||||
# exclude_unset: bool = True,
|
||||
# ):
|
||||
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(locals())
|
||||
# ### BEGIN ### API User ### get_user_obj_order_list() ###
|
||||
# Working well as of 2021-06-28. Using as a template for other routes.
|
||||
@router.get('/{user_id}/order_list', response_model=Resp_Body_Base)
|
||||
async def get_user_obj_order_list(
|
||||
user_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
|
||||
from_datetime: datetime.datetime = None,
|
||||
to_datetime: datetime.datetime = None,
|
||||
# inc_address: bool = False,
|
||||
# inc_contact: bool = False,
|
||||
inc_order_cfg: bool = False,
|
||||
inc_order_line_list: bool = False,
|
||||
status: str = 'complete',
|
||||
# inc_person: bool = False,
|
||||
# inc_order_list: bool = False,
|
||||
# inc_order_cart_list: bool = False,
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# user_obj = load_user_obj(
|
||||
# user_id=user_id,
|
||||
# inc_roles=inc_roles,
|
||||
# inc_contact=inc_contact,
|
||||
# inc_organization=inc_organization,
|
||||
# inc_person=inc_person
|
||||
# ).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
# data = user_obj
|
||||
# return mk_resp(data=data)
|
||||
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
|
||||
else:
|
||||
return mk_resp(data=None, status_code=404)
|
||||
|
||||
# Updated 2021-06-28
|
||||
if order_rec_list_result := get_order_rec_list(
|
||||
for_obj_type = 'user',
|
||||
for_obj_id = user_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
from_datetime = from_datetime,
|
||||
to_datetime = to_datetime,
|
||||
status = status,
|
||||
):
|
||||
order_result_list = []
|
||||
for order_rec in order_rec_list_result:
|
||||
if load_order_result := load_order_obj(
|
||||
order_id = order_rec.get('order_id', None),
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
inc_order_cfg = inc_order_cfg,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
):
|
||||
order_result_list.append(load_order_result)
|
||||
else:
|
||||
order_result_list.append(None)
|
||||
response_data = order_result_list
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data)
|
||||
# ### END ### API User ### get_user_obj_order_list() ###
|
||||
|
||||
|
||||
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
||||
|
||||
Reference in New Issue
Block a user