Working on the basic SQL select API CRUD
This commit is contained in:
@@ -13,6 +13,20 @@ from app.db import *
|
|||||||
from .user_model import *
|
from .user_model import *
|
||||||
from .response_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'
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@@ -37,10 +51,11 @@ async def get_obj_li(object_l1: str=None, object_l2: str=None, object_l3: str=No
|
|||||||
return response_data
|
return response_data
|
||||||
|
|
||||||
|
|
||||||
@router.get('/{object_l1}/{object_id}')
|
#@router.get('/{obj_type_l1}/{object_id_int}')
|
||||||
@router.get('/{object_l1}/{object_l2}/{object_id}')
|
@router.get('/{obj_type_l1}/{object_id}')
|
||||||
@router.get('/{object_l1}/{object_l2}/{object_l3}/{object_id}')
|
@router.get('/{obj_type_l1}/{object_l2}/{object_id}')
|
||||||
async def get_obj(object_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}/{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(...),
|
||||||
qry_str: Optional[str] = Query(None, max_length=50),
|
qry_str: Optional[str] = Query(None, max_length=50),
|
||||||
qry_int: Optional[int] = None,
|
qry_int: Optional[int] = None,
|
||||||
by_alias: Optional[bool] = True,
|
by_alias: Optional[bool] = True,
|
||||||
@@ -49,16 +64,26 @@ async def get_obj(object_l1: str=None, object_l2: str=None, object_l3: str=None,
|
|||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
log.debug(by_alias)
|
debug_data = {}
|
||||||
log.debug(exclude_unset)
|
debug_data['obj_type_l1'] = obj_type_l1
|
||||||
log.debug(qry_str)
|
debug_data['object_l2'] = object_l2
|
||||||
log.debug(qry_int)
|
debug_data['object_l3'] = object_l3
|
||||||
|
debug_data['object_id'] = object_id
|
||||||
|
#debug_data['object_id_int'] = object_id_int
|
||||||
|
#debug_data['object_id_rand'] = object_id_rand
|
||||||
|
|
||||||
response_data = {}
|
log.debug(debug_data)
|
||||||
response_data['object_l1'] = object_l1
|
|
||||||
response_data['object_l2'] = object_l2
|
if obj_type_l1 in obj_l1_type_li:
|
||||||
response_data['object_l3'] = object_l3
|
object_type = obj_l1_type_li[obj_type_l1]
|
||||||
response_data['object_id'] = object_id
|
else:
|
||||||
|
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)
|
||||||
|
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 = {}
|
||||||
data['id_random'] = 1
|
data['id_random'] = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user