Working on membership, fundraising, and products
This commit is contained in:
@@ -648,7 +648,7 @@ async def get_account_obj_post_list(
|
||||
for_obj_id = account_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
archive_on = archive_on
|
||||
archive_on = archive_on,
|
||||
):
|
||||
post_result_list = []
|
||||
for post_rec in post_rec_list_result:
|
||||
|
||||
@@ -11,6 +11,8 @@ 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 app.methods.product_methods import get_product_rec_list, load_product_obj
|
||||
|
||||
from app.models.product_models import Product_Base
|
||||
from app.models.response_models import *
|
||||
|
||||
@@ -18,7 +20,7 @@ from app.models.response_models import *
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post('', response_model=Resp_Body_Base)
|
||||
@router.post('/product', response_model=Resp_Body_Base)
|
||||
async def post_product_obj(
|
||||
obj: Product_Base,
|
||||
x_account_id: str = Header(...),
|
||||
@@ -41,7 +43,7 @@ async def post_product_obj(
|
||||
return result
|
||||
|
||||
|
||||
@router.patch('/{obj_id}', response_model=Resp_Body_Base)
|
||||
@router.patch('/product/{obj_id}', response_model=Resp_Body_Base)
|
||||
async def patch_product_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
obj: Product_Base = None,
|
||||
@@ -68,11 +70,13 @@ async def patch_product_obj(
|
||||
return result
|
||||
|
||||
|
||||
@router.get('/list', response_model=Resp_Body_Base)
|
||||
@router.get('/product/list', response_model=Resp_Body_Base)
|
||||
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),
|
||||
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
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
@@ -80,60 +84,87 @@ async def get_product_obj_li(
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
obj_type = 'product'
|
||||
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"""
|
||||
elif for_obj_type == 'event' 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`.for_type = :for_obj_type AND `product`.for_id = :for_obj_id"""
|
||||
else: sql_for_obj_type = ''
|
||||
|
||||
if prod_type in ['event', 'event_option', 'event_registration', 'fundraising', 'membership_group', 'membership_type']:
|
||||
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}
|
||||
"""
|
||||
|
||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(data)
|
||||
log.debug(sql)
|
||||
|
||||
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)
|
||||
if for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name=for_obj_type): pass
|
||||
else:
|
||||
log.debug(sql_result)
|
||||
return mk_resp(data=False, status_code=404)
|
||||
return mk_resp(data=None, status_code=404)
|
||||
|
||||
response_data = None
|
||||
|
||||
# Updated 2021-07-01
|
||||
if product_rec_list_result := get_product_rec_list(
|
||||
for_obj_type = for_obj_type,
|
||||
for_obj_id = for_obj_id,
|
||||
prod_type = prod_type,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
):
|
||||
product_result_list = []
|
||||
for product_rec in product_rec_list_result:
|
||||
if load_product_result := load_product_obj(
|
||||
product_id = product_rec.get('product_id', None),
|
||||
limit = limit,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
):
|
||||
product_result_list.append(load_product_result)
|
||||
else:
|
||||
product_result_list.append(None)
|
||||
response_data = product_result_list
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data)
|
||||
|
||||
|
||||
@router.get('/{obj_id}', response_model=Resp_Body_Base)
|
||||
@router.get('/account/{account_id}/product/list', response_model=Resp_Body_Base)
|
||||
async def get_account_product_obj_li(
|
||||
account_id: str = Query(..., min_length=1, max_length=22),
|
||||
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),
|
||||
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
|
||||
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())
|
||||
|
||||
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 for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name=for_obj_type): pass
|
||||
else: pass
|
||||
|
||||
# Updated 2021-07-01
|
||||
if product_rec_list_result := get_product_rec_list(
|
||||
account_id = account_id,
|
||||
for_obj_type = for_obj_type,
|
||||
for_obj_id = for_obj_id,
|
||||
prod_type = prod_type,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
):
|
||||
product_result_list = []
|
||||
for product_rec in product_rec_list_result:
|
||||
if load_product_result := load_product_obj(
|
||||
product_id = product_rec.get('product_id', None),
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
):
|
||||
product_result_list.append(load_product_result)
|
||||
else:
|
||||
product_result_list.append(None)
|
||||
response_data = product_result_list
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data)
|
||||
|
||||
|
||||
@router.get('/product/{obj_id}', response_model=Resp_Body_Base)
|
||||
async def get_product_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
x_account_id: str = Header(...),
|
||||
@@ -153,7 +184,7 @@ async def get_product_obj(
|
||||
return result
|
||||
|
||||
|
||||
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
||||
@router.delete('/product/{obj_id}', response_model=Resp_Body_Base)
|
||||
async def delete_product_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
x_account_id: str = Header(...),
|
||||
|
||||
Reference in New Issue
Block a user