Working on the basic SQL select API CRUD
This commit is contained in:
@@ -14,17 +14,49 @@ from .user_model import *
|
||||
from .response_model import *
|
||||
|
||||
|
||||
obj_l1_type_li = {}
|
||||
obj_l1_type_li['account'] = 'v_account'
|
||||
obj_l1_type_li['address'] = 'v_address'
|
||||
obj_l1_type_li['archive'] = 'v_archive'
|
||||
obj_l1_type_li['contact'] = 'v_contact'
|
||||
obj_l1_type_li['event'] = 'v_event'
|
||||
obj_l1_type_li['order'] = 'v_order'
|
||||
obj_l1_type_li['organization'] = 'v_organization'
|
||||
obj_l1_type_li['person'] = 'v_person'
|
||||
obj_l1_type_li['site'] = 'v_site'
|
||||
obj_l1_type_li['user'] = 'v_user'
|
||||
obj_type_li = {}
|
||||
obj_type_li['account'] = 'v_account'
|
||||
obj_type_li['activity_log'] = 'activity_log'
|
||||
obj_type_li['address'] = 'v_address'
|
||||
obj_type_li['archive'] = 'v_archive'
|
||||
obj_type_li['archive_content'] = 'v_archive_content'
|
||||
obj_type_li['contact'] = 'v_contact'
|
||||
obj_type_li['event'] = 'v_event'
|
||||
obj_type_li['event_badge'] = 'v_event_badge'
|
||||
obj_type_li['event_exhibit'] = 'v_event_exhibit'
|
||||
obj_type_li['event_location'] = 'v_event_location'
|
||||
obj_type_li['event_presentation'] = 'v_event_presentation'
|
||||
obj_type_li['event_presenter'] = 'v_event_presenter'
|
||||
obj_type_li['event_session'] = 'v_event_session'
|
||||
obj_type_li['event_track'] = 'v_event_track'
|
||||
obj_type_li['hosted_file'] = 'v_hosted_file'
|
||||
obj_type_li['journal'] = 'v_journal'
|
||||
obj_type_li['log'] = 'log' #'v_log'
|
||||
obj_type_li['log_client_viewing'] = 'log_client_viewing'
|
||||
obj_type_li['message'] = 'message' #'v_message'
|
||||
obj_type_li['order'] = 'v_order'
|
||||
obj_type_li['order_cart'] = 'v_order_cart'
|
||||
obj_type_li['order_cart_line'] = 'v_order_cart_line'
|
||||
obj_type_li['order_line'] = 'v_order_line'
|
||||
obj_type_li['order_transaction'] = 'order_transaction'
|
||||
obj_type_li['organization'] = 'v_organization'
|
||||
obj_type_li['page'] = 'page'
|
||||
obj_type_li['person'] = 'v_person'
|
||||
obj_type_li['post'] = 'v_post_detail'
|
||||
obj_type_li['post_comment'] = 'v_post_comment_detail'
|
||||
obj_type_li['product'] = 'v_product'
|
||||
obj_type_li['site'] = 'v_site'
|
||||
obj_type_li['site_domain'] = 'v_site_domain'
|
||||
obj_type_li['user'] = 'v_user'
|
||||
|
||||
obj_type_li['lu_education_degree'] = 'lu_education_degree'
|
||||
obj_type_li['lu_education_level'] = 'lu_education_level'
|
||||
obj_type_li['lu_html_color'] = 'lu_html_color'
|
||||
obj_type_li['lu_time_zone'] = 'v_lu_time_zone'
|
||||
obj_type_li['lu_user_status'] = 'lu_user_status'
|
||||
|
||||
obj_type_li['stripe_customer'] = 'stripe_customer'
|
||||
obj_type_li['stripe_log'] = 'stripe_log'
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
@@ -51,11 +83,11 @@ async def get_obj_li(object_l1: str=None, object_l2: str=None, object_l3: str=No
|
||||
return response_data
|
||||
|
||||
|
||||
#@router.get('/{obj_type_l1}/{object_id_int}')
|
||||
@router.get('/{obj_type_l1}/{object_id}')
|
||||
@router.get('/{obj_type_l1}/{object_l2}/{object_id}')
|
||||
@router.get('/{obj_type_l1}/{object_l2}/{object_l3}/{object_id}')
|
||||
async def get_obj(obj_type_l1: str=None, object_l2: str=None, object_l3: str=None, object_id: str=None, x_account_id: str = Header(...),
|
||||
#@router.get('/{obj_type_l1}/{obj_id_int}')
|
||||
@router.get('/{obj_type_l1}/{obj_id}')
|
||||
@router.get('/{obj_type_l1}/{obj_type_l2}/{obj_id}')
|
||||
@router.get('/{obj_type_l1}/{obj_type_l2}/{obj_type_l3}/{obj_id}')
|
||||
async def get_obj(obj_type_l1: str=None, obj_type_l2: str=None, obj_type_l3: str=None, obj_id: str=None, x_account_id: str = Header(...),
|
||||
qry_str: Optional[str] = Query(None, max_length=50),
|
||||
qry_int: Optional[int] = None,
|
||||
by_alias: Optional[bool] = True,
|
||||
@@ -66,40 +98,39 @@ async def get_obj(obj_type_l1: str=None, object_l2: str=None, object_l3: str=Non
|
||||
|
||||
debug_data = {}
|
||||
debug_data['obj_type_l1'] = obj_type_l1
|
||||
debug_data['object_l2'] = object_l2
|
||||
debug_data['object_l3'] = object_l3
|
||||
debug_data['object_id'] = object_id
|
||||
debug_data['obj_type_l2'] = obj_type_l2
|
||||
debug_data['obj_type_l3'] = obj_type_l3
|
||||
debug_data['obj_id'] = obj_id
|
||||
#debug_data['object_id_int'] = object_id_int
|
||||
#debug_data['object_id_rand'] = object_id_rand
|
||||
|
||||
log.debug(debug_data)
|
||||
|
||||
if obj_type_l1 in obj_l1_type_li:
|
||||
object_type = obj_l1_type_li[obj_type_l1]
|
||||
if obj_type_l1 and obj_type_l2 and obj_type_l3:
|
||||
obj_name = f'{obj_type_l1}_{obj_type_l2}_{obj_type_l3}'
|
||||
if obj_name in obj_type_li:
|
||||
table_name = obj_type_li[obj_name]
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400)
|
||||
elif obj_type_l1 and obj_type_l2:
|
||||
obj_name = f'{obj_type_l1}_{obj_type_l2}'
|
||||
if obj_name in obj_type_li:
|
||||
table_name = obj_type_li[obj_name]
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400)
|
||||
elif obj_type_l1:
|
||||
obj_name = f'{obj_type_l1}'
|
||||
if obj_name in obj_type_li:
|
||||
table_name = obj_type_li[obj_name]
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400)
|
||||
else:
|
||||
log.warning('We should not be here')
|
||||
return mk_resp(data=False, status_code=400)
|
||||
|
||||
# NOTE: Add a check for the object ID... assuming it is a random ID string for now.
|
||||
sql_result = sql_select(table_name=object_type, record_id_random=object_id)
|
||||
sql_result = sql_select(table_name=table_name, record_id_random=obj_id)
|
||||
log.debug(sql_result)
|
||||
resp_data = User_Base(**sql_result).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
return mk_resp(data=resp_data)#, details=debug_data)
|
||||
|
||||
data = {}
|
||||
data['id_random'] = 1
|
||||
|
||||
sql_select_str = f"""
|
||||
SELECT `user`.id AS 'user_id', `user`.id_random AS 'user_id_random', username, name, email, super
|
||||
FROM `user` AS `user`
|
||||
WHERE `user`.id = :id_random;
|
||||
"""
|
||||
|
||||
#sql_result = sql_select(table_name='user', record_id=1)
|
||||
sql_result = sql_select(sql=sql_select_str, data=data)
|
||||
resp_data = User_Base(**sql_result).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
|
||||
#response_data['sql_result'] = sql_result
|
||||
|
||||
resp = mk_resp(data=resp_data)
|
||||
|
||||
return resp
|
||||
|
||||
Reference in New Issue
Block a user