Working on the cart and other related things
This commit is contained in:
@@ -12,7 +12,7 @@ from app.db_sql import *
|
||||
from .api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||
|
||||
from ..models.order_cart_model import Order_Cart_Base
|
||||
from ..models.order_cart_methods import load_order_cart_obj
|
||||
from ..models.order_cart_methods import update_order_cart_obj, load_order_cart_obj
|
||||
from ..models.response_model import *
|
||||
|
||||
|
||||
@@ -42,31 +42,51 @@ async def post_order_cart_obj(
|
||||
return result
|
||||
|
||||
|
||||
@router.patch('/{obj_id}', response_model=Resp_Body_Base)
|
||||
@router.patch('/{order_cart_id}', response_model=Resp_Body_Base)
|
||||
async def patch_order_cart_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
obj: Order_Cart_Base = None,
|
||||
order_cart_id: str = Query(..., min_length=1, max_length=22),
|
||||
order_cart_obj: Order_Cart_Base = None,
|
||||
x_account_id: Optional[str] = Header(..., ),
|
||||
return_obj: Optional[bool] = True,
|
||||
inc_order_cart_line_li: Optional[bool] = True,
|
||||
inc_order_cart_cfg: Optional[bool] = True,
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
obj_type = 'order_cart'
|
||||
obj_data_dict = obj.dict(by_alias=False, exclude_unset=True)
|
||||
obj_data_dict['id'] = redis_lookup_id_random(record_id_random=obj_id, table_name=obj_type)
|
||||
obj_data_dict['id_random'] = obj_id
|
||||
result = patch_obj_template(
|
||||
obj_type=obj_type,
|
||||
data=obj_data_dict,
|
||||
obj_id=obj_id,
|
||||
return_obj=True,
|
||||
by_alias=True,
|
||||
exclude_unset=True,
|
||||
)
|
||||
return result
|
||||
order_cart_obj_up_result = update_order_cart_obj(order_cart_obj)
|
||||
if isinstance(order_cart_obj_up_result, int):
|
||||
log.info(f'Order cart update and the result was an int: {order_cart_obj_up_result}')
|
||||
pass
|
||||
elif isinstance(order_cart_obj_up_result, bool) and order_cart_obj_up_result:
|
||||
log.info(f'Order cart update and the result was an bool: {order_cart_obj_up_result}')
|
||||
pass
|
||||
elif isinstance(order_cart_obj_up_result, bool) and not order_cart_obj_up_result:
|
||||
log.error(f'Order cart update and the result was an bool: {order_cart_obj_up_result}')
|
||||
return mk_resp(data=False, status_code=500) # Internal Server Error
|
||||
|
||||
if order_cart_obj := load_order_cart_obj(order_cart_id=order_cart_id, inc_order_cart_line_li=inc_order_cart_line_li, inc_order_cart_cfg=inc_order_cart_cfg):
|
||||
data = order_cart_obj.dict(by_alias=True, exclude_unset=False)
|
||||
return mk_resp(data=data)
|
||||
else:
|
||||
return mk_resp(data=False, status_code=404) # Not Found
|
||||
|
||||
|
||||
# obj_type = 'order_cart'
|
||||
# obj_data_dict = obj.dict(by_alias=False, exclude_unset=True)
|
||||
# obj_data_dict['id'] = redis_lookup_id_random(record_id_random=obj_id, table_name=obj_type)
|
||||
# obj_data_dict['id_random'] = obj_id
|
||||
# result = patch_obj_template(
|
||||
# obj_type=obj_type,
|
||||
# data=obj_data_dict,
|
||||
# obj_id=order_cart_id,
|
||||
# return_obj=True,
|
||||
# by_alias=True,
|
||||
# exclude_unset=True,
|
||||
# )
|
||||
# return result
|
||||
|
||||
|
||||
@router.get('/list', response_model=Resp_Body_Base)
|
||||
@@ -202,4 +222,4 @@ async def delete_order_cart_obj(
|
||||
obj_type=obj_type,
|
||||
obj_id=obj_id,
|
||||
)
|
||||
return result
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user