Moving things to use the common_route_params. Rewriting most of things order and order_cart related! Updating address and contact related. General code clean up.
This commit is contained in:
@@ -453,7 +453,7 @@ def sql_select(
|
||||
as_dict: bool|None = True,
|
||||
as_list: bool|None = False,
|
||||
max_count: int = 100000,
|
||||
) -> None|bool|list:
|
||||
) -> None|bool|dict|list:
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from app.models.common_field_schema import default_num_bytes
|
||||
|
||||
|
||||
# ### BEGIN ### API Address Methods ### load_address_obj() ###
|
||||
@logger_reset
|
||||
def load_address_obj(
|
||||
address_id:int|str,
|
||||
enabled: str = 'enabled', # enabled, disabled, all # Probably not needed for the address
|
||||
@@ -54,7 +55,7 @@ def get_address_rec_list(
|
||||
limit: int = 500,
|
||||
offset: int = 0,
|
||||
) -> list|bool:
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if for_id := redis_lookup_id_random(record_id_random=for_id, table_name=for_type): pass
|
||||
@@ -98,6 +99,7 @@ def get_address_rec_list(
|
||||
# ### BEGIN ### API Address Methods ### create_update_address_obj_v4() ###
|
||||
# NOTE: This will create or update an address.
|
||||
# Rewrite and updated 2021-08-25
|
||||
@logger_reset
|
||||
def create_update_address_obj_v4(
|
||||
address_dict_obj: Address_Base|dict,
|
||||
address_id: int|str = None,
|
||||
@@ -221,6 +223,7 @@ def create_update_address_obj_v4(
|
||||
|
||||
# ### BEGIN ### API Address Methods ### create_address_obj() ###
|
||||
# Updated 2022-01-06
|
||||
@logger_reset
|
||||
def create_address_obj(
|
||||
account_id: int|str,
|
||||
address_dict_obj: Address_Base,
|
||||
@@ -295,6 +298,7 @@ def create_address_obj(
|
||||
|
||||
# ### BEGIN ### API Address Methods ### update_address_obj() ###
|
||||
# Updated 2022-01-06
|
||||
@logger_reset
|
||||
def update_address_obj(
|
||||
address_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||
address_dict_obj: Address_Base,
|
||||
@@ -361,6 +365,7 @@ def update_address_obj(
|
||||
|
||||
|
||||
# ### BEGIN ### API Address Methods ### create_update_address_obj() ###
|
||||
@logger_reset
|
||||
def create_update_address_obj(
|
||||
address_id: int|str|None, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||
address_obj: Address_Base,
|
||||
|
||||
@@ -14,6 +14,7 @@ from app.models.contact_models import Contact_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API Contact Methods ### load_contact_obj() ###
|
||||
@logger_reset
|
||||
def load_contact_obj(
|
||||
contact_id: int|str,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
@@ -24,7 +25,7 @@ def load_contact_obj(
|
||||
model_as_dict: bool = False,
|
||||
inc_address: bool = False
|
||||
) -> Contact_Base|dict|bool:
|
||||
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if contact_id := redis_lookup_id_random(record_id_random=contact_id, table_name='contact'): pass
|
||||
@@ -76,7 +77,7 @@ def get_contact_rec_list(
|
||||
limit: int = 500,
|
||||
offset: int = 0,
|
||||
) -> list|bool:
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if for_id := redis_lookup_id_random(record_id_random=for_id, table_name=for_type): pass
|
||||
@@ -118,6 +119,7 @@ def get_contact_rec_list(
|
||||
|
||||
# ### BEGIN ### API Contact Methods ### get_account_id_w_contact_id() ###
|
||||
# Updated 2021-08-24
|
||||
@logger_reset
|
||||
def get_account_id_w_contact_id(
|
||||
contact_id: int|str,
|
||||
) -> bool|int|None:
|
||||
@@ -137,9 +139,7 @@ def get_account_id_w_contact_id(
|
||||
LIMIT 1;
|
||||
"""
|
||||
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
if contact_data_result := sql_select(data=data, sql=sql):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(contact_data_result)
|
||||
if account_id := contact_data_result.get('account_id', None): return account_id
|
||||
else: return False
|
||||
@@ -151,6 +151,7 @@ def get_account_id_w_contact_id(
|
||||
# ### BEGIN ### API Contact Methods ### create_update_contact_obj_v4() ###
|
||||
# NOTE: This will create or update a contact.
|
||||
# Rewrite and updated 2021-08-25
|
||||
@logger_reset
|
||||
def create_update_contact_obj_v4(
|
||||
contact_dict_obj: Contact_Base|dict,
|
||||
contact_id: int|str = None,
|
||||
@@ -161,7 +162,7 @@ def create_update_contact_obj_v4(
|
||||
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
||||
return_outline: bool = False,
|
||||
) -> int|bool:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
log.info('Checking requirements...')
|
||||
@@ -307,6 +308,7 @@ def create_update_contact_obj_v4(
|
||||
# NOTE: This will create a contact and then also create a linked address if contact_obj.address data is passed.
|
||||
# NOTE: In the future it should be required that account_id, for_type, and for_id should be passed separately. account_id might not be required *if* it can be looked up based on for_type and for_id.
|
||||
# Updated 2022-01-06
|
||||
@logger_reset
|
||||
def create_contact_obj(
|
||||
account_id: int|str,
|
||||
contact_dict_obj: Contact_Base,
|
||||
@@ -316,7 +318,7 @@ def create_contact_obj(
|
||||
create_sub_obj: bool = False,
|
||||
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
||||
) -> int|bool:
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# ### SECTION ### Secondary data validation
|
||||
@@ -347,31 +349,6 @@ def create_contact_obj(
|
||||
|
||||
contact_dict = contact_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'address', 'address_id', 'address_id_random', 'created_on', 'updated_on'})
|
||||
|
||||
# log.debug(type(contact_dict_obj))
|
||||
# if isinstance(contact_dict_obj, dict):
|
||||
# if account_id:
|
||||
# contact_dict_obj['account_id'] = account_id
|
||||
# if for_type:
|
||||
# contact_dict_obj['for_type'] = for_type
|
||||
# if for_id:
|
||||
# contact_dict_obj['for_id'] = for_id
|
||||
# try:
|
||||
# contact_obj = Contact_Base(**contact_dict_obj)
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(contact_obj)
|
||||
# except ValidationError as e:
|
||||
# log.error(e.json())
|
||||
# return False
|
||||
# else:
|
||||
# if account_id:
|
||||
# contact_obj.account_id = account_id
|
||||
# if for_type:
|
||||
# contact_obj.for_type = for_type
|
||||
# if for_id:
|
||||
# contact_obj.for_id = for_id
|
||||
|
||||
# contact_dict = contact_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'address', 'created_on', 'updated_on'})
|
||||
|
||||
# ### SECTION ### Process data
|
||||
# Look for an account_id in the contact_obj
|
||||
if account_id: pass
|
||||
@@ -451,6 +428,7 @@ def create_contact_obj(
|
||||
# ### BEGIN ### API Contact Methods ### update_contact_obj() ###
|
||||
# NOTE: This will update a contact and then also create or update a linked address if contact_obj.address data is passed.
|
||||
# Updated 2022-01-06
|
||||
@logger_reset
|
||||
def update_contact_obj(
|
||||
contact_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||
contact_dict_obj: Contact_Base,
|
||||
@@ -539,127 +517,14 @@ def update_contact_obj(
|
||||
else: return False
|
||||
else: pass
|
||||
|
||||
# log.debug(contact_obj_up)
|
||||
# log.debug(contact_obj_up.dict(by_alias=True, exclude_unset=True))
|
||||
log.debug(contact_obj.dict(by_alias=False, exclude_unset=True))
|
||||
# log.debug(contact_obj_up.dict(by_alias=False, exclude_unset=False))
|
||||
|
||||
#contact_dict_up = contact_obj_up.dict(by_alias=False, exclude_unset=True)
|
||||
|
||||
# if contact_obj_up.address:
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# address_obj_unknown = contact_obj_up.address
|
||||
# log.debug(address_obj_unknown)
|
||||
# if isinstance(contact_obj_up.address, dict):
|
||||
# address_id = address_obj_unknown.get('address_id_random', None)
|
||||
# else:
|
||||
# address_id = address_obj_unknown.id
|
||||
|
||||
# if address_id:
|
||||
# # from app.methods.address_methods import update_address_obj_v3
|
||||
# if update_address_obj_result := update_address_obj(
|
||||
# address_id = address_id,
|
||||
# address_obj_up = address_obj_unknown,
|
||||
# create_sub_obj = create_sub_obj,
|
||||
# fail_any = fail_any,
|
||||
# ):
|
||||
# address_id = update_address_obj_result
|
||||
# log.info(f'Address updated. Address ID: {address_id}')
|
||||
# else:
|
||||
# log.warning(f'Address not updated. Contact ID: {contact_id}')
|
||||
# log.debug(update_address_obj_result)
|
||||
# address_id = None
|
||||
# if fail_any: return False
|
||||
|
||||
# if isinstance(update_address_obj_result, int):
|
||||
# address_id = update_address_obj_result
|
||||
# log.info(f'Address updated. Address ID: {address_id}')
|
||||
# else:
|
||||
# log.warning(f'Address not updated. Contact ID: {contact_id}')
|
||||
# log.debug(update_address_obj_result)
|
||||
# address_id = None
|
||||
# if fail_any: return False
|
||||
# else:
|
||||
# log.info(f'No Address ID found.')
|
||||
# # from app.methods.address_methods import create_address_obj_v3
|
||||
# if create_address_obj_result := create_address_obj(
|
||||
# account_id = account_id,
|
||||
# for_type = 'contact',
|
||||
# for_id = contact_id,
|
||||
# address_obj_new = address_obj_unknown,
|
||||
# fail_any = fail_any,
|
||||
# ):
|
||||
# if isinstance(create_address_obj_result, int):
|
||||
# address_id = create_address_obj_result
|
||||
# log.info(f'Address created. Address ID: {address_id}')
|
||||
# else:
|
||||
# log.warning(f'Address not created. Contact ID: {contact_id}')
|
||||
# log.debug(create_address_obj_result)
|
||||
# address_id = None
|
||||
# if fail_any: return False
|
||||
# else:
|
||||
# log.warning(f'Address not created. Contact ID: {contact_id}')
|
||||
# log.debug(create_address_obj_result)
|
||||
# address_id = None
|
||||
# if fail_any: return False
|
||||
# # return_dict['address_id'] = address_id
|
||||
# else:
|
||||
# log.info('Address not found or not in a dict.')
|
||||
# pass
|
||||
|
||||
|
||||
|
||||
# if contact_obj_up.address_id and contact_obj_up.address:
|
||||
# address_id = contact_obj_up.address_id
|
||||
# address_obj_up = contact_obj_up.address
|
||||
# log.debug(address_id)
|
||||
# log.debug(address_obj_up)
|
||||
# if address_obj_up_result := update_address_obj(
|
||||
# address_id = address_id,
|
||||
# address_obj_up = address_obj_up,
|
||||
# create_sub_obj = create_sub_obj,
|
||||
# ):
|
||||
# log.debug(address_obj_up_result)
|
||||
# else:
|
||||
# log.debug(address_obj_up_result)
|
||||
# return False
|
||||
# elif contact_obj_up.address and not contact_obj_up.address.id:
|
||||
# # NOTE: This will blindly create a new address even if there was one associated but the contact_obj.address_id was not found.
|
||||
# address_obj_in = contact_obj_up.address
|
||||
# log.debug(address_obj_in)
|
||||
# if address_obj_in_result := create_address_obj(
|
||||
# address_obj_new = address_obj_in,
|
||||
# account_id = account_id,
|
||||
# for_type = 'contact',
|
||||
# for_id = contact_id,
|
||||
# ):
|
||||
# # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(address_obj_in_result)
|
||||
# # NOTE: This last update should no longer be needed now that the contact_obj.address_id is not supposed to be used.
|
||||
# # Need to update the contact with the new address_id
|
||||
# contact_obj_up.address_id = address_obj_in_result # REMOVE
|
||||
# else:
|
||||
# # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(address_obj_in_result)
|
||||
# return False
|
||||
|
||||
|
||||
|
||||
# contact_dict_up = contact_obj_up.dict(by_alias=False, exclude_unset=True, exclude={'address'})
|
||||
# log.debug(contact_dict_up)
|
||||
|
||||
# if contact_obj_up_result := sql_update(data=contact_dict_up, table_name='contact', rm_id_random=True):
|
||||
# log.debug(contact_obj_up_result)
|
||||
# return True
|
||||
# else:
|
||||
# log.debug(contact_obj_up_result)
|
||||
# return False
|
||||
|
||||
return True
|
||||
# ### END ### API Contact Methods ### update_contact_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Contact Methods ### create_update_contact_obj() ###
|
||||
@logger_reset
|
||||
def create_update_contact_obj(
|
||||
contact_id: int|str|None, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||
contact_obj: Contact_Base,
|
||||
|
||||
@@ -4,7 +4,7 @@ import datetime
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
||||
from app.db_sql import redis_lookup_id_random, sql_delete, sql_enable_part, sql_insert, sql_limit_offset_part, sql_select, sql_update
|
||||
from app.lib_general import log, logging
|
||||
|
||||
|
||||
@@ -35,9 +35,11 @@ def create_order_line_obj(order_line_obj_new:Order_Line_Base):
|
||||
|
||||
|
||||
# ### BEGIN ### API Order Line Methods ### load_order_line_obj() ###
|
||||
# Updated 2021-11-19
|
||||
def load_order_line_obj(
|
||||
order_line_id: int|str,
|
||||
limit: int = 1000,
|
||||
# limit: int = 500,
|
||||
# offset: int = 0,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True, # NOTE: Normally this is True
|
||||
model_as_dict: bool = False, # NOTE: Normally this is False
|
||||
@@ -50,16 +52,14 @@ def load_order_line_obj(
|
||||
|
||||
if order_line_rec := sql_select(table_name='v_order_line', record_id=order_line_id): pass
|
||||
else: return False
|
||||
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(order_line_rec)
|
||||
|
||||
try:
|
||||
order_line_obj = Order_Line_Base(**order_line_rec)
|
||||
log.debug(order_line_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
return False
|
||||
log.debug(order_line_obj)
|
||||
|
||||
if model_as_dict:
|
||||
return order_line_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
||||
@@ -72,6 +72,8 @@ def load_order_line_obj(
|
||||
# Updated 2021-11-22
|
||||
def load_order_line_obj_full_detail(
|
||||
order_line_rec: dict,
|
||||
# limit: int = 500,
|
||||
# offset: int = 0,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True, # NOTE: Normally this is True
|
||||
model_as_dict: bool = False, # NOTE: Normally this is False
|
||||
@@ -166,7 +168,8 @@ def get_order_line_rec_list(
|
||||
status: str = 'closed', # started, in progress, complete, all
|
||||
full_detail: bool = False,
|
||||
# enabled: str = 'enabled', # enabled, disabled, all
|
||||
limit: int = 1000,
|
||||
limit: int = 500,
|
||||
offset: int = 0,
|
||||
) -> list|bool:
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
@@ -228,11 +231,8 @@ def get_order_line_rec_list(
|
||||
else:
|
||||
sql_from_to_datetime = ''
|
||||
|
||||
if limit:
|
||||
data['limit'] = limit
|
||||
sql_limit = f'LIMIT :limit'
|
||||
else:
|
||||
sql_limit = ''
|
||||
# sql_enabled, data['enable'] = sql_enable_part(table_name='order', enabled=enabled) # Reasonably safe return str and bool
|
||||
sql_limit = sql_limit_offset_part(limit=limit, offset=offset) # Reasonably safe return str
|
||||
|
||||
log.debug(data)
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from app.db_sql import redis_lookup_id_random, sql_delete, sql_insert_or_update, sql_select
|
||||
from app.lib_general import log, logging
|
||||
from app.db_sql import redis_lookup_id_random, sql_delete, sql_enable_part, sql_insert_or_update, sql_limit_offset_part, sql_select
|
||||
from app.lib_general import log, logging, logger_reset
|
||||
|
||||
from app.methods.order_cfg_methods import load_order_cfg_obj
|
||||
from app.methods.order_line_methods import get_order_line_rec_list, load_order_line_obj
|
||||
@@ -19,6 +19,7 @@ from app.models.order_line_models import Order_Line_Base, Order_Line_DB_Base # T
|
||||
|
||||
|
||||
# ### BEGIN ### API Order Methods ### save_order_obj() ###
|
||||
# @logger_reset
|
||||
def save_order_obj(order_obj_new:Order_Base, repl_order_line_li:bool=False):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
@@ -174,6 +175,7 @@ def save_order_obj(order_obj_new:Order_Base, repl_order_line_li:bool=False):
|
||||
|
||||
# ### BEGIN ### API Order Methods ### load_order_obj() ###
|
||||
# Updated 2021-11-19
|
||||
# @logger_reset
|
||||
def load_order_obj(
|
||||
order_id: int|str,
|
||||
inc_address: bool = False,
|
||||
@@ -188,24 +190,23 @@ def load_order_obj(
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
model_as_dict: bool = False,
|
||||
):
|
||||
) -> None|bool|dict|list:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if order_id := redis_lookup_id_random(record_id_random=order_id, table_name='order'): pass
|
||||
else: return False
|
||||
else: return False # None, false bool
|
||||
|
||||
if order_rec := sql_select(table_name='v_order', record_id=order_id): pass
|
||||
else: return False
|
||||
|
||||
#log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
else: return order_rec # None, empty dict, empty list, false bool
|
||||
log.debug(order_rec)
|
||||
|
||||
try:
|
||||
order_obj = Order_Base(**order_rec)
|
||||
log.debug(order_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
return False
|
||||
log.debug(order_obj)
|
||||
|
||||
# Updated 2022-01-18
|
||||
if inc_order_cfg:
|
||||
@@ -233,7 +234,6 @@ def load_order_obj(
|
||||
order_line_result_list.append(
|
||||
load_order_line_obj(
|
||||
order_line_id = order_line_rec.get('order_line_id'),
|
||||
limit = limit,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
model_as_dict = model_as_dict,
|
||||
@@ -287,6 +287,7 @@ def load_order_obj(
|
||||
|
||||
# ### BEGIN ### API Order Methods ### get_order_rec_list() ###
|
||||
# Updated 2021-12-13
|
||||
# @logger_reset
|
||||
def get_order_rec_list(
|
||||
for_obj_type: str,
|
||||
for_obj_id: str,
|
||||
@@ -294,6 +295,7 @@ def get_order_rec_list(
|
||||
to_datetime: datetime.datetime = None,
|
||||
# balance_gt: int = 0, # $0 to $99999
|
||||
status: str = 'closed', # started, in progress, complete, all
|
||||
# checkout_status: str = 'none', # none, canceled, waiting, success, failed, unknown
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
limit: int = 500,
|
||||
offset: int = 0,
|
||||
@@ -307,10 +309,10 @@ def get_order_rec_list(
|
||||
data = {}
|
||||
if for_obj_type == 'account' and for_obj_id:
|
||||
data['account_id'] = redis_lookup_id_random(record_id_random=for_obj_id, table_name='account')
|
||||
sql_account_person_user = f"""`order`.account_id = :account_id"""
|
||||
sql_obj_type_id = f'`order`.account_id = :account_id'
|
||||
elif for_obj_type == 'person' and for_obj_id:
|
||||
data['person_id'] = redis_lookup_id_random(record_id_random=for_obj_id, table_name='person')
|
||||
sql_account_person_user = f"""`order`.person_id = :person_id"""
|
||||
sql_obj_type_id = f'`order`.person_id = :person_id'
|
||||
else:
|
||||
return False
|
||||
|
||||
@@ -347,7 +349,7 @@ def get_order_rec_list(
|
||||
else:
|
||||
sql_from_to_datetime = ''
|
||||
|
||||
sql_enabled, data['enable'] = sql_enable_part(table_name='contact', enabled=enabled) # Reasonably safe return str and bool
|
||||
sql_enabled, data['enable'] = sql_enable_part(table_name='order', enabled=enabled) # Reasonably safe return str and bool
|
||||
sql_limit = sql_limit_offset_part(limit=limit, offset=offset) # Reasonably safe return str
|
||||
|
||||
log.debug(data)
|
||||
|
||||
@@ -128,21 +128,19 @@ def load_person_obj(
|
||||
else:
|
||||
if person_rec := sql_select(table_name='v_person', record_id=person_id): pass
|
||||
else: return person_rec # None or False
|
||||
|
||||
log.debug(person_rec)
|
||||
|
||||
try:
|
||||
person_obj = Person_Base(**person_rec)
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(person_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
return False
|
||||
log.debug(person_obj)
|
||||
|
||||
# Updated 2021-12-14
|
||||
if inc_contact:
|
||||
log.info('Need to include contact data...')
|
||||
contact_id = person_rec.get('contact_id', None)
|
||||
contact_id = person_rec.get('contact_id')
|
||||
log.debug(contact_id)
|
||||
if contact_result := load_contact_obj(
|
||||
contact_id = contact_id,
|
||||
|
||||
@@ -88,11 +88,15 @@ def mk_resp(
|
||||
|
||||
if response:
|
||||
log.debug(response)
|
||||
if status_code == 400: response.status_code = status.HTTP_400_BAD_REQUEST
|
||||
if status_code == 400:
|
||||
log.warning('Likely bad request')
|
||||
response.status_code = status.HTTP_400_BAD_REQUEST
|
||||
elif status_code == 401: response.status_code = status.HTTP_401_UNAUTHORIZED
|
||||
# elif status_code == 402: response.status_code = status.HTTP_402_X
|
||||
elif status_code == 403: response.status_code = status.HTTP_403_FORBIDDEN
|
||||
elif status_code == 404: response.status_code = status.HTTP_404_NOT_FOUND
|
||||
elif status_code == 404:
|
||||
log.info('No results')
|
||||
response.status_code = status.HTTP_404_NOT_FOUND
|
||||
elif status_code == 408: response.status_code = status.HTTP_408_REQUEST_TIMEOUT
|
||||
elif status_code == 429: response.status_code = status.HTTP_429_TOO_MANY_REQUESTS
|
||||
elif status_code == 500: response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
|
||||
@@ -63,7 +63,6 @@ async def get_obj_id_order_line_list(
|
||||
if not full_detail:
|
||||
if load_order_line_result := load_order_line_obj(
|
||||
order_line_id = order_line_rec.get('order_line_id', None),
|
||||
limit = limit,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
|
||||
@@ -29,8 +29,8 @@ async def post_order_obj(
|
||||
|
||||
inc_address: bool = False,
|
||||
inc_contact: bool = False,
|
||||
inc_person: bool = False,
|
||||
inc_order_line_list: bool = True,
|
||||
inc_person: bool = False,
|
||||
return_obj: bool = True,
|
||||
|
||||
commons: Common_Route_Params = Depends(common_route_params),
|
||||
@@ -40,33 +40,40 @@ async def post_order_obj(
|
||||
|
||||
# ### SECTION ### Secondary data validation
|
||||
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
|
||||
# elif person_id is None: pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The person ID was invalid or not found.')
|
||||
|
||||
# ### SECTION ### Process data
|
||||
if order_id := create_order(
|
||||
if order_id := create_order_obj(
|
||||
account_id = commons.x_account_id,
|
||||
person_id = person_id,
|
||||
order_dict_obj = order_obj,
|
||||
): pass
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=commons.response, status_message='Something failed while processing the data.') # Bad Request
|
||||
|
||||
# ### SECTION ### Return successful results
|
||||
if return_obj:
|
||||
order_obj = load_order_obj(
|
||||
order_id = order_id,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_person = inc_person,
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
data = order_obj
|
||||
if load_order_obj_result := load_order_obj(
|
||||
order_id = order_id,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
inc_person = inc_person,
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset):
|
||||
log.info('Loading successful. Returning result')
|
||||
log.debug(load_order_obj_result)
|
||||
return mk_resp(data=load_order_obj_result, response=commons.response)
|
||||
elif isinstance(load_order_obj_result, list) or load_order_obj_result is None: # Empty list or None
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
else:
|
||||
order_id_random = get_id_random(record_id=order_id, table_name='order')
|
||||
data = {}
|
||||
data['order_id'] = order_id
|
||||
data['order_id_random'] = order_id_random
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
# ### END ### API Order Routers ### post_order_obj() ###
|
||||
|
||||
|
||||
@@ -77,12 +84,12 @@ async def post_order_obj(
|
||||
async def patch_order_obj(
|
||||
order_obj: Order_Base,
|
||||
order_id: str = Query(..., min_length=11, max_length=22),
|
||||
person_id: str = Query(None, min_length=11, max_length=22),
|
||||
# person_id: str = Query(None, min_length=11, max_length=22),
|
||||
|
||||
inc_address: bool = False,
|
||||
inc_contact: bool = False,
|
||||
inc_person: bool = False,
|
||||
inc_order_line_list: bool = True,
|
||||
inc_person: bool = False,
|
||||
return_obj: Optional[bool] = True,
|
||||
|
||||
commons: Common_Route_Params = Depends(common_route_params),
|
||||
@@ -95,64 +102,50 @@ async def patch_order_obj(
|
||||
# person_id_random = person_id # This is used later for the response data
|
||||
|
||||
if order_id := redis_lookup_id_random(record_id_random=order_id, table_name='order'): pass
|
||||
elif order_id is None: pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The order ID was invalid or not found.')
|
||||
|
||||
# if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
|
||||
# elif person_id is None: pass
|
||||
# else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The person ID was invalid or not found.')
|
||||
|
||||
# ### SECTION ### Process data
|
||||
if order_update_result := update_order(
|
||||
if update_order_obj_result := update_order_obj(
|
||||
order_id = order_id,
|
||||
order_dict_obj = order_obj,
|
||||
# person_id = person_id,
|
||||
): pass
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=commons.response, status_message='Something failed while processing the data.') # Bad Request
|
||||
|
||||
# ### SECTION ### Return successful results
|
||||
if return_obj:
|
||||
order_obj = load_order_obj(
|
||||
order_id = order_id,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
inc_person = inc_person,
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
data = order_obj
|
||||
if load_order_obj_result := load_order_obj(
|
||||
order_id = order_id,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
inc_person = inc_person,
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset):
|
||||
log.info('Loading successful. Returning result')
|
||||
log.debug(load_order_obj_result)
|
||||
return mk_resp(data=load_order_obj_result, response=commons.response)
|
||||
elif isinstance(load_order_obj_result, list) or load_order_obj_result is None: # Empty list or None
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
else:
|
||||
data = {}
|
||||
data['order_id'] = order_id
|
||||
data['order_id_random'] = order_id_random
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
# ### END ### API Order Routers ### patch_order_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Order Routers ### delete_order_obj() ###
|
||||
# Updated 2022-01-18
|
||||
@router.delete('/order/{order_id}', response_model=Resp_Body_Base)
|
||||
async def delete_order_obj(
|
||||
order_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 = 'order'
|
||||
result = delete_obj_template(
|
||||
obj_type = obj_type,
|
||||
obj_id = obj_id,
|
||||
)
|
||||
return result
|
||||
# ### END ### API Order Routers ### delete_order_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Order Routers ### patch_order_obj_add_line() ###
|
||||
# Updated 2022-01-18
|
||||
@router.patch('/v3/order/{order_id}/line/add', response_model=Resp_Body_Base)
|
||||
async def patch_order_obj_add_line(
|
||||
order_obj: Order_Base,
|
||||
order_line_obj: Order_Line_Base,
|
||||
order_id: str = Query(..., min_length=11, max_length=22),
|
||||
|
||||
# inc_order: bool = False,
|
||||
@@ -171,26 +164,38 @@ async def patch_order_obj_add_line(
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The order ID was invalid or not found.')
|
||||
|
||||
# ### SECTION ### Process data
|
||||
if order_line_add_result := add_order_line(
|
||||
if order_line_id := add_order_obj_line(
|
||||
order_id = order_id,
|
||||
order_line_dict_obj = order_line_obj,
|
||||
): pass
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=commons.response, status_message='Something failed while processing the data.') # Bad Request
|
||||
|
||||
# ### SECTION ### Return successful results
|
||||
if return_obj:
|
||||
order_obj = load_order_obj(
|
||||
order_id = order_id,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
data = order_obj
|
||||
if load_order_obj_result := load_order_obj(
|
||||
order_id = order_id,
|
||||
# inc_address = inc_address,
|
||||
# inc_contact = inc_contact,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
# inc_person = inc_person,
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset):
|
||||
log.info('Loading successful. Returning result')
|
||||
log.debug(load_order_obj_result)
|
||||
return mk_resp(data=load_order_obj_result, response=commons.response)
|
||||
elif isinstance(load_order_obj_result, list) or load_order_obj_result is None: # Empty list or None
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
else:
|
||||
order_line_id = order_line_add_result
|
||||
order_line_id_random = get_id_random(record_id=order_line_id, table_name='order_line')
|
||||
data = {}
|
||||
data['order_id'] = order_id
|
||||
data['order_id_random'] = order_id_random
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
data['order_line_id'] = order_line_id
|
||||
data['order_line_id_random'] = order_line_id_random
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
# ### END ### API Order Routers ### patch_order_obj_add_line() ###
|
||||
|
||||
|
||||
@@ -222,26 +227,36 @@ async def patch_order_obj_update_line(
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The order line ID was invalid or not found.')
|
||||
|
||||
# ### SECTION ### Process data
|
||||
if order_line_update_result := update_order_line(
|
||||
if update_order_obj_line_result := update_order_obj_line(
|
||||
order_line_id = order_line_id,
|
||||
order_line_dict_obj = order_line_obj,
|
||||
): pass
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=commons.response, status_message='Something failed while processing the data.') # Bad Request
|
||||
|
||||
# ### SECTION ### Return successful results
|
||||
if return_obj:
|
||||
order_obj = load_order_obj(
|
||||
order_id = order_id,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
data = order_obj
|
||||
if load_order_obj_result := load_order_obj(
|
||||
order_id = order_id,
|
||||
# inc_address = inc_address,
|
||||
# inc_contact = inc_contact,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
# inc_person = inc_person,
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset):
|
||||
log.info('Loading successful. Returning result')
|
||||
log.debug(order_dict)
|
||||
return mk_resp(data=order_dict, response=commons.response)
|
||||
elif isinstance(load_order_obj_result, list) or load_order_obj_result is None: # Empty list or None
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
else:
|
||||
data = {}
|
||||
data['order_id'] = order_id
|
||||
data['order_id_random'] = order_id_random
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
data['order_line_id'] = order_line_id
|
||||
data['order_line_id_random'] = order_line_id_random
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
# ### END ### API Order Routers ### patch_order_obj_update_line() ###
|
||||
|
||||
|
||||
@@ -273,25 +288,35 @@ async def patch_order_obj_remove_line(
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The order line ID was invalid or not found.')
|
||||
|
||||
# ### SECTION ### Process data
|
||||
if order_line_remove_result := remove_order_line(
|
||||
if remove_order_obj_line_result := remove_order_obj_line(
|
||||
order_line_id = order_line_id,
|
||||
): pass
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=commons.response, status_message='Something failed while processing the data.') # Bad Request
|
||||
|
||||
# ### SECTION ### Return successful results
|
||||
if return_obj:
|
||||
order_obj = load_order_obj(
|
||||
order_id = order_id,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset)
|
||||
data = order_obj
|
||||
if load_order_obj_result := load_order_obj(
|
||||
order_id = order_id,
|
||||
# inc_address = inc_address,
|
||||
# inc_contact = inc_contact,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
# inc_person = inc_person,
|
||||
).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset):
|
||||
log.info('Loading successful. Returning result')
|
||||
log.debug(order_dict)
|
||||
return mk_resp(data=order_dict, response=commons.response)
|
||||
elif isinstance(load_order_obj_result, list) or load_order_obj_result is None: # Empty list or None
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
else:
|
||||
data = {}
|
||||
data['order_id'] = order_id
|
||||
data['order_id_random'] = order_id_random
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
data['order_line_id'] = order_line_id
|
||||
data['order_line_id_random'] = order_line_id_random
|
||||
return mk_resp(data=data, response=commons.response)
|
||||
# ### END ### API Order Routers ### patch_order_obj_remove_line() ###
|
||||
|
||||
|
||||
@@ -302,36 +327,45 @@ async def get_order_obj_li(
|
||||
for_obj_type: str = Query(..., min_length=2, max_length=50),
|
||||
for_obj_id: str = Query(..., min_length=11, max_length=22),
|
||||
order_status: str = 'complete',
|
||||
order_checkout_status: str = 'complete',
|
||||
from_datetime: datetime.datetime = None,
|
||||
to_datetime: datetime.datetime = None,
|
||||
inc_order_line_list: bool = False,
|
||||
|
||||
inc_address: bool = False,
|
||||
inc_contact: bool = False,
|
||||
inc_order_cfg: bool = False,
|
||||
inc_person_obj: bool = False,
|
||||
inc_order_line_list: bool = False,
|
||||
inc_person: bool = False,
|
||||
|
||||
commons: Common_Route_Params = Depends(common_route_params),
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if obj_type in ['account', 'person']: pass
|
||||
else: return mk_resp(data=False, status_code=400, response=response, status_message='The object type passed was invalid or not found. Expecting "account" or "person".') # Bad Request
|
||||
|
||||
if obj_type_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name=for_obj_type): pass
|
||||
else: return mk_resp(data=False, status_code=404, response=commons.response) # Not Found
|
||||
|
||||
if order_rec_list_result := get_order_rec_list(
|
||||
if get_order_rec_list_result := get_order_rec_list(
|
||||
for_obj_type = for_obj_type,
|
||||
for_obj_id = for_obj_id,
|
||||
from_datetime = from_datetime,
|
||||
to_datetime = to_datetime,
|
||||
status = status,
|
||||
status = order_status,
|
||||
# checkout_status = order_checkout_status,
|
||||
enabled = commons.enabled,
|
||||
limit = commons.limit,
|
||||
offset = commons.offset,
|
||||
):
|
||||
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),
|
||||
order_obj_list = []
|
||||
for order_rec in get_order_rec_list_result:
|
||||
if load_order_obj_result := load_order_obj(
|
||||
order_id = order_rec.get('order_id'),
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_order_cfg = inc_order_cfg,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
inc_person = inc_person,
|
||||
enabled = commons.enabled,
|
||||
@@ -340,291 +374,106 @@ async def get_order_obj_li(
|
||||
exclude_unset = commons.exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
):
|
||||
order_result_list.append(load_order_result)
|
||||
log.debug(load_order_obj_result)
|
||||
order_obj_list.append(load_order_obj_result)
|
||||
else:
|
||||
order_result_list.append(None)
|
||||
response_data = order_result_list
|
||||
elif isinstance(order_rec_list_result, list) or order_rec_list_result is None: # Empty list or None
|
||||
log.info('No results')
|
||||
order_obj_list.append(None)
|
||||
log.info('Loading successful. Returning result')
|
||||
log.debug(order_obj_list)
|
||||
return mk_resp(data=order_obj_list, response=commons.response)
|
||||
elif isinstance(get_order_rec_list_result, list) or get_order_rec_list_result is None: # Empty list or None
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data, response=commons.response)
|
||||
# ### END ### API Order Routers ### get_order_obj_li() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Order Routes ### get_order_obj() ###
|
||||
# NOTE 2021-08-09: Use with rework of order_cart
|
||||
# Updated 2021-08-07
|
||||
@router.get('/order/{order_id}', response_model=Resp_Body_Base)
|
||||
# Updated 2022-12-18
|
||||
@router.get('/v3/order/{order_id}', response_model=Resp_Body_Base)
|
||||
async def get_order_obj(
|
||||
order_id: str = Query(..., min_length=11, max_length=22),
|
||||
limit: int = 500,
|
||||
enabled: str = 'enabled',
|
||||
inc_order_line_list: bool = False,
|
||||
|
||||
inc_address: bool = False,
|
||||
inc_contact: bool = False,
|
||||
inc_order_cfg: bool = False,
|
||||
inc_order_line_list: bool = False,
|
||||
inc_person: bool = False,
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
response: Response = Response,
|
||||
|
||||
commons: Common_Route_Params = Depends(common_route_params),
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if order_obj := load_order_obj(
|
||||
if order_id := redis_lookup_id_random(record_id_random=order_id, table_name='order'): pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The order ID was invalid or not found.')
|
||||
|
||||
if load_order_obj_result := load_order_obj(
|
||||
order_id = order_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_order_cfg = inc_order_cfg,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
inc_person = inc_person,
|
||||
limit = commons.limit,
|
||||
enabled = commons.enabled,
|
||||
by_alias = commons.by_alias,
|
||||
exclude_unset = commons.exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
):
|
||||
log.debug(order_obj)
|
||||
data = order_obj.dict(by_alias=by_alias, exclude_unset=False) # NOTE NOTE NOTE NOTE exclude_unset is forced to False for now. Will return more fields than is ideal. Need to create another Order_Line_Base. Probably Order_Line_OUT_Base
|
||||
return mk_resp(data=data)
|
||||
log.debug(load_order_obj_result)
|
||||
order_dict = load_order_obj_result.dict(by_alias=by_alias, exclude_unset=False) # NOTE NOTE NOTE NOTE exclude_unset is forced to False for now. Will return more fields than is ideal. Need to create another Order_Line_Base. Probably Order_Line_OUT_Base
|
||||
log.info('Loading successful. Returning result')
|
||||
return mk_resp(data=order_dict, response=commons.response)
|
||||
elif isinstance(load_order_obj_result, list) or load_order_obj_result is None: # Empty list or None
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
else:
|
||||
return mk_resp(data=False, status_code=404, response=response) # Not Found
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
# ### END ### API Order Routes ### get_order_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Order ### get_obj_id_order_list() ###
|
||||
# Updated 2021-12-13
|
||||
@router.get('/{obj_type}/{obj_id}/order/list', response_model=Resp_Body_Base)
|
||||
async def get_obj_id_order_list(
|
||||
obj_type: str = Query(..., min_length=4, max_length=25), # Expects account or person
|
||||
obj_id: str = Query(..., min_length=11, max_length=22),
|
||||
from_datetime: datetime.datetime = None,
|
||||
to_datetime: datetime.datetime = None,
|
||||
inc_order_cfg: bool = False,
|
||||
inc_order_line_list: bool = False,
|
||||
# w_prod_type: str = 'all', # all, cont_edu_cert, event, fundraising, membership, etc
|
||||
inc_person: bool = False,
|
||||
status: str = 'closed', # open, locked, reopened?, closed (complete), canceled, other
|
||||
enabled: str = 'enabled',
|
||||
limit: int = 50,
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
x_account_id: str = Header(..., min_length=11, max_length=22),
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if obj_type in ['account', 'person']:
|
||||
if obj_id := redis_lookup_id_random(record_id_random=obj_id, table_name=obj_type): pass
|
||||
else: return mk_resp(data=None, status_code=404, response=response)
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
||||
|
||||
if order_rec_list_result := get_order_rec_list(
|
||||
for_obj_type = obj_type,
|
||||
for_obj_id = obj_id,
|
||||
from_datetime = from_datetime,
|
||||
to_datetime = to_datetime,
|
||||
status = status,
|
||||
enabled = enabled,
|
||||
limit = limit,
|
||||
):
|
||||
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),
|
||||
inc_order_cfg = inc_order_cfg,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
inc_person = inc_person,
|
||||
enabled = enabled,
|
||||
limit = limit,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
):
|
||||
order_result_list.append(load_order_result)
|
||||
else:
|
||||
order_result_list.append(None)
|
||||
response_data = order_result_list
|
||||
elif isinstance(order_rec_list_result, list) or order_rec_list_result is None: # Empty list or None
|
||||
log.info('No results')
|
||||
return mk_resp(data=None, status_code=404, response=response) # Not Found
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data, response=response)
|
||||
# ### END ### API Order ### get_obj_id_order_list() ###
|
||||
|
||||
|
||||
# # ### BEGIN ### API Order ### get_account_obj_order_list() ###
|
||||
# # Updated 2021-11-19
|
||||
# @router.get('/account/{account_id}/order/list', response_model=Resp_Body_Base)
|
||||
# async def get_account_id_order_list(
|
||||
# account_id: str = Query(..., min_length=11, max_length=22),
|
||||
# limit: int = 50,
|
||||
# enabled: str = 'enabled',
|
||||
# from_datetime: datetime.datetime = None,
|
||||
# to_datetime: datetime.datetime = None,
|
||||
# inc_order_cfg: bool = False,
|
||||
# inc_order_line_list: bool = False,
|
||||
# # inc_order_w_prod_type: str = 'all', # all, membership, fundraising, event, etc
|
||||
# status: str = 'closed', # open, locked, reopened?, closed (complete), canceled, other
|
||||
# x_account_id: str = Header(...),
|
||||
# by_alias: Optional[bool] = True,
|
||||
# exclude_unset: Optional[bool] = True,
|
||||
# response: Response = Response,
|
||||
# ):
|
||||
# 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=response)
|
||||
|
||||
# # Updated 2021-06-28
|
||||
# if order_rec_list_result := get_order_rec_list(
|
||||
# for_obj_type = 'account',
|
||||
# for_obj_id = account_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, response=response) # Bad Request
|
||||
|
||||
# return mk_resp(data=response_data)
|
||||
# # ### END ### API Order ### get_account_obj_order_list() ###
|
||||
|
||||
|
||||
# # ### BEGIN ### API Order ### get_person_obj_order_list() ###
|
||||
# # Updated 2021-11-19
|
||||
# @router.get('/person/{person_id}/order/list', response_model=Resp_Body_Base)
|
||||
# async def get_person_id_order_list(
|
||||
# person_id: str = Query(..., min_length=11, max_length=22),
|
||||
# limit: int = 50,
|
||||
# enabled: str = 'enabled',
|
||||
# from_datetime: datetime.datetime = None,
|
||||
# to_datetime: datetime.datetime = None,
|
||||
# inc_order_cfg: bool = False,
|
||||
# inc_order_line_list: bool = False,
|
||||
# # inc_order_w_prod_type: str = 'all', # all, membership, fundraising, event, etc
|
||||
# status: str = 'closed', # open, locked, reopened?, closed (complete), canceled, other
|
||||
# x_account_id: str = Header(...),
|
||||
# by_alias: Optional[bool] = True,
|
||||
# exclude_unset: Optional[bool] = True,
|
||||
# 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, response=response)
|
||||
|
||||
# # Updated 2021-06-28
|
||||
# if order_rec_list_result := get_order_rec_list(
|
||||
# for_obj_type = 'person',
|
||||
# for_obj_id = person_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, response=response) # Bad Request
|
||||
|
||||
# return mk_resp(data=response_data)
|
||||
# # ### END ### API Order ### get_person_obj_order_list() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Order ### get_person_id_order_cart() ###
|
||||
# NOTE 2021-08-09: Use with rework of order_cart. The most recent (hopefully only one) "open" order for a person.
|
||||
# Updated 2021-11-19
|
||||
@router.get('/person/{person_id}/order/cart', response_model=Resp_Body_Base)
|
||||
# Updated 2022-12-18
|
||||
@router.get('/v3/person/{person_id}/order/cart', response_model=Resp_Body_Base)
|
||||
async def get_person_id_order_cart(
|
||||
person_id: str = Query(..., min_length=11, max_length=22),
|
||||
enabled: str = 'enabled',
|
||||
inc_order_line_list: bool = False,
|
||||
inc_order_cfg: bool = False,
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
response: Response = Response,
|
||||
|
||||
commons: Common_Route_Params = Depends(common_route_params),
|
||||
):
|
||||
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, response=commons.response, status_message='The person ID was invalid or not found.')
|
||||
|
||||
# Query to get the one "open" order status for a person ID
|
||||
|
||||
return False
|
||||
# ### END ### API Order ### get_person_id_order_cart() ###
|
||||
|
||||
|
||||
@router.delete('/order/{obj_id}', response_model=Resp_Body_Base)
|
||||
# ### BEGIN ### API Order Routers ### delete_order_obj() ###
|
||||
# Updated 2022-01-18
|
||||
@router.delete('/v3/order/{order_id}', response_model=Resp_Body_Base)
|
||||
async def delete_order_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
x_account_id: str = Header(...),
|
||||
response: Response = Response,
|
||||
order_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())
|
||||
|
||||
if order_id := redis_lookup_id_random(record_id_random=order_id, table_name='order'): pass
|
||||
else: return mk_resp(data=None, status_code=404, response=commons.response, status_message='The order ID was invalid or not found.')
|
||||
|
||||
obj_type = 'order'
|
||||
result = delete_obj_template(
|
||||
obj_type=obj_type,
|
||||
obj_id=obj_id,
|
||||
obj_type = obj_type,
|
||||
obj_id = obj_id,
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
# NOTE 2021-08-09: Use with rework of order_cart
|
||||
# NOTE: The router needs to have the prefix (/order) removed.
|
||||
@router.delete('/order/{order_id}/line/<order_line_id>/remove', response_model=Resp_Body_Base)
|
||||
async def delete_order_line_obj_NOT_SURE(
|
||||
order_id: str = Query(..., min_length=1, max_length=22),
|
||||
obj: Order_Base = None,
|
||||
x_account_id: Optional[str] = Header(..., ),
|
||||
return_obj: Optional[bool] = True,
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
# ### END ### API Order Routers ### delete_order_obj() ###
|
||||
@@ -379,23 +379,15 @@ async def get_person_obj(
|
||||
inc_post_comment_list = inc_post_comment_list,
|
||||
inc_user = inc_user,
|
||||
):
|
||||
response_data = person_rec_result
|
||||
# if isinstance(person_rec_result, dict):
|
||||
# response_data = person_rec_result
|
||||
# else:
|
||||
# response_data = person_rec_result
|
||||
# else:
|
||||
# return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
|
||||
log.info('Loading successful. Returning result')
|
||||
return mk_resp(data=person_rec_result, response=commons.response)
|
||||
elif isinstance(person_rec_result, list) or person_rec_result is None: # Empty list or None
|
||||
log.info('No results')
|
||||
if auth_key: log.info('It is likely the auth_key did not match.')
|
||||
return mk_resp(data=False, status_code=404, response=commons.response) # Not Found
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data, response=commons.response)
|
||||
# ### END ### API Person ### get_person_obj() ###
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user