Work order_cart and related
This commit is contained in:
@@ -72,6 +72,7 @@ async def patch_product_obj(
|
||||
async def get_product_obj_li(
|
||||
for_obj_type: Optional[str] = Query(None, min_length=2, max_length=50),
|
||||
for_obj_id: Optional[str] = Query(None, min_length=1, max_length=22),
|
||||
prod_type: Optional[str] = Query(None, min_length=2, max_length=50),
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
@@ -80,14 +81,43 @@ async def get_product_obj_li(
|
||||
log.debug(locals())
|
||||
|
||||
obj_type = 'product'
|
||||
result = get_obj_li_template(
|
||||
obj_type=obj_type,
|
||||
for_obj_type=for_obj_type,
|
||||
for_obj_id=for_obj_id,
|
||||
by_alias=True,
|
||||
exclude_unset=True,
|
||||
)
|
||||
return result
|
||||
base_name = Product_Base
|
||||
data = {}
|
||||
|
||||
if for_obj_type == 'account' and for_obj_id:
|
||||
for_obj_id_random = for_obj_id
|
||||
for_obj_id = redis_lookup_id_random(record_id_random=for_obj_id_random, table_name=for_obj_type)
|
||||
|
||||
data['for_obj_type'] = for_obj_type
|
||||
data['for_obj_id'] = for_obj_id
|
||||
data['for_obj_id_random'] = for_obj_id_random
|
||||
|
||||
sql_for_obj_type = f"""`product`.account_id = :for_obj_id"""
|
||||
else: sql_for_obj_type = ''
|
||||
|
||||
if prod_type in ['event', 'event option', 'membership', 'fundraising']:
|
||||
data['type_name'] = prod_type
|
||||
|
||||
sql_product_type = f"""AND product.type_name = :type_name"""
|
||||
else: sql_product_type = ''
|
||||
|
||||
sql = f"""
|
||||
SELECT *
|
||||
FROM `v_product` AS product
|
||||
WHERE {sql_for_obj_type}
|
||||
{sql_product_type}
|
||||
"""
|
||||
|
||||
if sql_result := sql_select(data=data, sql=sql, as_list=True):
|
||||
resp_data_li = []
|
||||
for record in sql_result:
|
||||
resp_data = base_name(**record).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
resp_data_li.append(resp_data)
|
||||
|
||||
return mk_resp(data=resp_data_li)
|
||||
else:
|
||||
log.debug(sql_result)
|
||||
return mk_resp(data=False, status_code=404)
|
||||
|
||||
|
||||
@router.get('/{obj_id}', response_model=Resp_Body_Base)
|
||||
|
||||
Reference in New Issue
Block a user