Working on general POST and PATCH template functions.
This commit is contained in:
@@ -270,7 +270,18 @@ def sql_insert_or_update(sql:str=None, data:dict=None, table_name:str=None, rm_i
|
|||||||
# ### BEGIN ### Core Help CRUD ### sql_select() ###
|
# ### BEGIN ### Core Help CRUD ### sql_select() ###
|
||||||
# The catch all SQL SELECT function - STI 2021-02-17
|
# The catch all SQL SELECT function - STI 2021-02-17
|
||||||
# This one does it all for SQL SELECT queries
|
# This one does it all for SQL SELECT queries
|
||||||
def sql_select(table_name=None, record_id=None, record_id_random=None, field_name=None, field_value=None, sql=None, data=None, rm_id_random=None, as_dict=True, as_list=None):
|
def sql_select(
|
||||||
|
table_name=None,
|
||||||
|
record_id=None,
|
||||||
|
record_id_random=None,
|
||||||
|
field_name=None,
|
||||||
|
field_value=None,
|
||||||
|
sql=None,
|
||||||
|
data=None,
|
||||||
|
rm_id_random=None,
|
||||||
|
as_dict=True,
|
||||||
|
as_list=None
|
||||||
|
):
|
||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
@@ -475,7 +486,15 @@ def sql_select(table_name=None, record_id=None, record_id_random=None, field_nam
|
|||||||
# ### BEGIN ### Core Help CRUD ### sql_delete() ###
|
# ### BEGIN ### Core Help CRUD ### sql_delete() ###
|
||||||
# The catch all SQL DELETE function - STI 2021-02-17
|
# The catch all SQL DELETE function - STI 2021-02-17
|
||||||
# This one does it all for SQL DELETE queries
|
# This one does it all for SQL DELETE queries
|
||||||
def sql_delete(table_name:str=None, record_id:int=None, record_id_random:str=None, field_name:str=None, field_value=None, sql:str=None, data:dict=None):
|
def sql_delete(
|
||||||
|
table_name:str=None,
|
||||||
|
record_id:int=None,
|
||||||
|
record_id_random:str=None,
|
||||||
|
field_name:str=None,
|
||||||
|
field_value=None,
|
||||||
|
sql:str=None,
|
||||||
|
data:dict=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())
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from ..log import *
|
|||||||
from app.config import settings
|
from app.config import settings
|
||||||
from app.db_sql import *
|
from app.db_sql import *
|
||||||
|
|
||||||
from .api_crud import patch_obj_template
|
from .api_crud import post_obj_template, patch_obj_template
|
||||||
|
|
||||||
from ..models.address_model import Address_Base
|
from ..models.address_model import Address_Base
|
||||||
from ..models.response_model import *
|
from ..models.response_model import *
|
||||||
@@ -18,102 +18,53 @@ from ..models.response_model import *
|
|||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
# Working on the address API CRUD - STI 2021-03-08
|
|
||||||
|
|
||||||
|
|
||||||
@router.post('')
|
@router.post('')
|
||||||
async def post_address_obj(address: Address_Base,
|
async def post_address_obj(
|
||||||
x_account_id: str = Header(...),
|
obj: Address_Base,
|
||||||
return_obj: Optional[bool] = True,
|
x_account_id: str = Header(...),
|
||||||
by_alias: Optional[bool] = True,
|
return_obj: Optional[bool] = True,
|
||||||
exclude_unset: Optional[bool] = True,
|
by_alias: Optional[bool] = True,
|
||||||
):
|
exclude_unset: Optional[bool] = True,
|
||||||
|
):
|
||||||
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())
|
||||||
|
|
||||||
table_name_insert = 'address'
|
table_name_insert = 'address'
|
||||||
obj_data_dict = address.dict(by_alias=False, exclude_unset=True)
|
obj_data_dict = obj.dict(by_alias=False, exclude_unset=True)
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
result = post_obj_template(
|
||||||
log.debug(obj_data_dict)
|
table_name_insert=table_name_insert,
|
||||||
obj_data = lookup_id_random_pop(obj_data_dict)
|
data=obj_data_dict,
|
||||||
base_name = Address_Base
|
return_obj=True,
|
||||||
|
by_alias=True,
|
||||||
if sql_insert_result := sql_insert(table_name=table_name_insert, data=obj_data):
|
exclude_unset=True
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
)
|
||||||
log.debug(sql_insert_result)
|
|
||||||
obj_id = sql_insert_result
|
|
||||||
else:
|
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(sql_insert_result)
|
|
||||||
return mk_resp(data=False, status_code=400)
|
|
||||||
|
|
||||||
table_name_select = 'v_address'
|
|
||||||
sql_select_result = sql_select(table_name=table_name_select, record_id=obj_id)
|
|
||||||
log.debug(sql_select_result)
|
|
||||||
|
|
||||||
resp_data = base_name(**sql_select_result).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
|
||||||
|
|
||||||
return mk_resp(data=resp_data)
|
|
||||||
|
|
||||||
|
|
||||||
@router.patch('/{address_id}')
|
|
||||||
async def patch_address_obj(
|
|
||||||
address_id: str,
|
|
||||||
address: Address_Base,
|
|
||||||
x_account_id: str = Header(...),
|
|
||||||
return_obj: Optional[bool] = True,
|
|
||||||
by_alias: Optional[bool] = True,
|
|
||||||
exclude_unset: Optional[bool] = True,
|
|
||||||
):
|
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(locals())
|
|
||||||
|
|
||||||
table_name_update = 'address'
|
|
||||||
obj_id = address_id # actually id_random
|
|
||||||
obj_data_dict = address.dict(by_alias=False, exclude_unset=True)
|
|
||||||
obj_data_dict['id'] = redis_lookup_id_random(record_id_random=obj_id, table_name=table_name_update)
|
|
||||||
obj_data_dict['id_random'] = obj_id
|
|
||||||
result = patch_obj_template(table_name_update=table_name_update,
|
|
||||||
data=obj_data_dict,
|
|
||||||
obj_id=obj_id,
|
|
||||||
return_obj=True,
|
|
||||||
by_alias=True,
|
|
||||||
exclude_unset=True
|
|
||||||
)
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
@router.patch('/{obj_id}')
|
||||||
|
async def patch_address_obj(
|
||||||
|
obj_id: str,
|
||||||
|
obj: Address_Base,
|
||||||
|
x_account_id: str = Header(...),
|
||||||
|
return_obj: 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())
|
log.debug(locals())
|
||||||
|
|
||||||
table_name_update = 'address'
|
table_name_update = 'address'
|
||||||
table_name_select = 'v_address'
|
obj_data_dict = obj.dict(by_alias=False, exclude_unset=True)
|
||||||
obj_id = address_id
|
|
||||||
obj_data_dict = address.dict(by_alias=False, exclude_unset=True)
|
|
||||||
obj_data_dict['id'] = redis_lookup_id_random(record_id_random=obj_id, table_name=table_name_update)
|
obj_data_dict['id'] = redis_lookup_id_random(record_id_random=obj_id, table_name=table_name_update)
|
||||||
obj_data_dict['id_random'] = address_id # NOTE: Adding this in so the id_random is NOT updated
|
obj_data_dict['id_random'] = obj_id
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
result = patch_obj_template(
|
||||||
log.debug(obj_data_dict)
|
table_name_update=table_name_update,
|
||||||
obj_data = lookup_id_random_pop(obj_data_dict)
|
data=obj_data_dict,
|
||||||
base_name = Address_Base
|
obj_id=obj_id,
|
||||||
|
return_obj=True,
|
||||||
|
by_alias=True,
|
||||||
|
exclude_unset=True
|
||||||
|
)
|
||||||
|
|
||||||
if sql_update_result := sql_update(table_name=table_name_update, data=obj_data):
|
return result
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(sql_update_result)
|
|
||||||
#obj_id = sql_update_result
|
|
||||||
obj_id = obj_data_dict['id']
|
|
||||||
else:
|
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(sql_update_result)
|
|
||||||
return mk_resp(data=False, status_code=400)
|
|
||||||
|
|
||||||
if sql_select_result := sql_select(table_name=table_name_select, record_id=obj_id):
|
|
||||||
log.debug(sql_select_result)
|
|
||||||
|
|
||||||
resp_data = base_name(**sql_select_result).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
|
||||||
|
|
||||||
return mk_resp(data=resp_data)
|
|
||||||
else:
|
|
||||||
log.debug(sql_select_result)
|
|
||||||
return mk_resp(data=False, status_code=404)
|
|
||||||
|
|||||||
@@ -123,16 +123,17 @@ router = APIRouter()
|
|||||||
@router.get('/{obj_type_l1}/list')
|
@router.get('/{obj_type_l1}/list')
|
||||||
@router.get('/{obj_type_l1}/{obj_type_l2}/list')
|
@router.get('/{obj_type_l1}/{obj_type_l2}/list')
|
||||||
@router.get('/{obj_type_l1}/{obj_type_l2}/{obj_type_l3}/list')
|
@router.get('/{obj_type_l1}/{obj_type_l2}/{obj_type_l3}/list')
|
||||||
async def get_obj_li(obj_type_l1: str=None,
|
async def get_obj_li(
|
||||||
obj_type_l2: str=None,
|
obj_type_l1: str=None,
|
||||||
obj_type_l3: str=None,
|
obj_type_l2: str=None,
|
||||||
obj_id: str=None,
|
obj_type_l3: str=None,
|
||||||
for_obj_type: Optional[str] = Query(None, max_length=50),
|
obj_id: str=None,
|
||||||
for_obj_id: Optional[str] = Query(None, max_length=22),
|
for_obj_type: Optional[str] = Query(None, max_length=50),
|
||||||
x_account_id: str = Header(...),
|
for_obj_id: Optional[str] = Query(None, max_length=22),
|
||||||
by_alias: Optional[bool] = True,
|
x_account_id: str = Header(...),
|
||||||
exclude_unset: Optional[bool] = True,
|
by_alias: Optional[bool] = True,
|
||||||
):
|
exclude_unset: Optional[bool] = True,
|
||||||
|
):
|
||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
@@ -196,18 +197,19 @@ async def get_obj_li(obj_type_l1: str=None,
|
|||||||
@router.get('/{obj_type_l1}/{obj_id}')
|
@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_id}')
|
||||||
@router.get('/{obj_type_l1}/{obj_type_l2}/{obj_type_l3}/{obj_id}')
|
@router.get('/{obj_type_l1}/{obj_type_l2}/{obj_type_l3}/{obj_id}')
|
||||||
async def get_obj(obj_type_l1: str=None,
|
async def get_obj(
|
||||||
obj_type_l2: str=None,
|
obj_type_l1: str=None,
|
||||||
obj_type_l3: str=None,
|
obj_type_l2: str=None,
|
||||||
obj_id: str=None,
|
obj_type_l3: str=None,
|
||||||
for_obj_type: Optional[str] = Query(None, max_length=50),
|
obj_id: str=None,
|
||||||
for_obj_id: Optional[str] = Query(None, max_length=22),
|
for_obj_type: Optional[str] = Query(None, max_length=50),
|
||||||
x_account_id: str = Header(...),
|
for_obj_id: Optional[str] = Query(None, max_length=22),
|
||||||
qry_str: Optional[str] = Query(None, max_length=50),
|
x_account_id: str = Header(...),
|
||||||
qry_int: Optional[int] = None,
|
qry_str: Optional[str] = Query(None, max_length=50),
|
||||||
by_alias: Optional[bool] = True,
|
qry_int: Optional[int] = None,
|
||||||
exclude_unset: Optional[bool] = True,
|
by_alias: Optional[bool] = True,
|
||||||
):
|
exclude_unset: Optional[bool] = True,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Simple select object type with an ID:
|
Simple select object type with an ID:
|
||||||
- **obj_type_l1, obj_type_l2, obj_type_l3**:
|
- **obj_type_l1, obj_type_l2, obj_type_l3**:
|
||||||
@@ -279,14 +281,15 @@ async def get_obj(obj_type_l1: str=None,
|
|||||||
@router.delete('/{obj_type_l1}/{obj_id}')
|
@router.delete('/{obj_type_l1}/{obj_id}')
|
||||||
@router.delete('/{obj_type_l1}/{obj_type_l2}/{obj_id}')
|
@router.delete('/{obj_type_l1}/{obj_type_l2}/{obj_id}')
|
||||||
@router.delete('/{obj_type_l1}/{obj_type_l2}/{obj_type_l3}/{obj_id}')
|
@router.delete('/{obj_type_l1}/{obj_type_l2}/{obj_type_l3}/{obj_id}')
|
||||||
async def delete_obj(obj_type_l1: str=None,
|
async def delete_obj(
|
||||||
obj_type_l2: str=None,
|
obj_type_l1: str=None,
|
||||||
obj_type_l3: str=None,
|
obj_type_l2: str=None,
|
||||||
obj_id: str=None,
|
obj_type_l3: str=None,
|
||||||
x_account_id: str = Header(...),
|
obj_id: str=None,
|
||||||
by_alias: Optional[bool] = True,
|
x_account_id: str = Header(...),
|
||||||
exclude_unset: Optional[bool] = True,
|
by_alias: Optional[bool] = True,
|
||||||
):
|
exclude_unset: Optional[bool] = True,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Simple delete object type with an ID:
|
Simple delete object type with an ID:
|
||||||
- **obj_type_l1, obj_type_l2, obj_type_l3**:
|
- **obj_type_l1, obj_type_l2, obj_type_l3**:
|
||||||
@@ -345,21 +348,55 @@ async def delete_obj(obj_type_l1: str=None,
|
|||||||
return mk_resp(data=resp_data) #, details=debug_data)
|
return mk_resp(data=resp_data) #, details=debug_data)
|
||||||
|
|
||||||
|
|
||||||
def patch_obj_template(table_name_update:str=None,
|
def post_obj_template(
|
||||||
data:dict=None,
|
table_name_insert:str=None,
|
||||||
obj_id:str=None,
|
data:dict=None,
|
||||||
return_obj:bool=True,
|
return_obj:bool=True,
|
||||||
by_alias:bool=True,
|
by_alias:bool=True,
|
||||||
exclude_unset:bool=True
|
exclude_unset:bool=True
|
||||||
):
|
):
|
||||||
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())
|
||||||
|
|
||||||
obj_data_dict = data
|
obj_data_dict = data
|
||||||
|
obj_data = lookup_id_random_pop(obj_data_dict)
|
||||||
|
table_name_select = obj_type_li[table_name_insert]['table_name']
|
||||||
|
base_name = obj_type_li[table_name_insert]['base_name']
|
||||||
|
|
||||||
|
if sql_insert_result := sql_insert(table_name=table_name_insert, data=obj_data):
|
||||||
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(sql_insert_result)
|
||||||
|
obj_id = sql_insert_result
|
||||||
|
else:
|
||||||
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(sql_insert_result)
|
||||||
|
return mk_resp(data=False, status_code=400)
|
||||||
|
|
||||||
|
if sql_select_result := sql_select(table_name=table_name_select, record_id=obj_id):
|
||||||
|
log.debug(sql_select_result)
|
||||||
|
|
||||||
|
resp_data = base_name(**sql_select_result).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||||
|
|
||||||
|
return mk_resp(data=resp_data)
|
||||||
|
else:
|
||||||
|
log.debug(sql_select_result)
|
||||||
|
return mk_resp(data=False, status_code=404)
|
||||||
|
|
||||||
|
|
||||||
|
def patch_obj_template(
|
||||||
|
table_name_update:str=None,
|
||||||
|
data:dict=None,
|
||||||
|
obj_id:str=None,
|
||||||
|
return_obj:bool=True,
|
||||||
|
by_alias:bool=True,
|
||||||
|
exclude_unset:bool=True
|
||||||
|
):
|
||||||
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
obj_data_dict = data
|
||||||
#obj_data_dict['id'] = redis_lookup_id_random(record_id_random=obj_id, table_name=table_name_update)
|
#obj_data_dict['id'] = redis_lookup_id_random(record_id_random=obj_id, table_name=table_name_update)
|
||||||
obj_data_dict['id_random'] = obj_id # NOTE: Adding this in so the id_random is NOT updated
|
obj_data_dict['id_random'] = obj_id # NOTE: Adding this in so the id_random is NOT updated
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(obj_data_dict)
|
log.debug(obj_data_dict)
|
||||||
obj_data = lookup_id_random_pop(obj_data_dict)
|
obj_data = lookup_id_random_pop(obj_data_dict)
|
||||||
table_name_select = obj_type_li[table_name_update]['table_name']
|
table_name_select = obj_type_li[table_name_update]['table_name']
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ from ..log import *
|
|||||||
from app.config import settings
|
from app.config import settings
|
||||||
from app.db_sql import *
|
from app.db_sql import *
|
||||||
|
|
||||||
|
from .api_crud import patch_obj_template
|
||||||
|
|
||||||
from ..models.contact_model import Contact_Base
|
from ..models.contact_model import Contact_Base
|
||||||
from ..models.response_model import *
|
from ..models.response_model import *
|
||||||
|
|
||||||
@@ -20,12 +22,13 @@ router = APIRouter()
|
|||||||
|
|
||||||
|
|
||||||
@router.post('')
|
@router.post('')
|
||||||
async def post_contact_obj(contact: Contact_Base,
|
async def post_contact_obj(
|
||||||
x_account_id: str = Header(...),
|
contact: Contact_Base,
|
||||||
return_obj: Optional[bool] = True,
|
x_account_id: str = Header(...),
|
||||||
by_alias: Optional[bool] = True,
|
return_obj: Optional[bool] = True,
|
||||||
exclude_unset: Optional[bool] = True,
|
by_alias: Optional[bool] = True,
|
||||||
):
|
exclude_unset: Optional[bool] = True,
|
||||||
|
):
|
||||||
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())
|
||||||
|
|
||||||
@@ -55,13 +58,14 @@ async def post_contact_obj(contact: Contact_Base,
|
|||||||
|
|
||||||
|
|
||||||
@router.patch('/{contact_id}')
|
@router.patch('/{contact_id}')
|
||||||
async def patch_contact_obj(contact_id: str,
|
async def patch_contact_obj(
|
||||||
contact: Contact_Base,
|
contact_id: str,
|
||||||
x_account_id: str = Header(...),
|
contact: Contact_Base,
|
||||||
return_obj: Optional[bool] = True,
|
x_account_id: str = Header(...),
|
||||||
by_alias: Optional[bool] = True,
|
return_obj: Optional[bool] = True,
|
||||||
exclude_unset: Optional[bool] = True,
|
by_alias: Optional[bool] = True,
|
||||||
):
|
exclude_unset: Optional[bool] = True,
|
||||||
|
):
|
||||||
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())
|
||||||
|
|
||||||
@@ -70,43 +74,13 @@ async def patch_contact_obj(contact_id: str,
|
|||||||
obj_data_dict = contact.dict(by_alias=False, exclude_unset=True)
|
obj_data_dict = contact.dict(by_alias=False, exclude_unset=True)
|
||||||
obj_data_dict['id'] = redis_lookup_id_random(record_id_random=obj_id, table_name=table_name_update)
|
obj_data_dict['id'] = redis_lookup_id_random(record_id_random=obj_id, table_name=table_name_update)
|
||||||
obj_data_dict['id_random'] = obj_id
|
obj_data_dict['id_random'] = obj_id
|
||||||
result = patch_obj_template(table_name_update=table_name_update,
|
result = patch_obj_template(
|
||||||
data=obj_data_dict,
|
table_name_update=table_name_update,
|
||||||
obj_id=obj_id,
|
data=obj_data_dict,
|
||||||
return_obj=True,
|
obj_id=obj_id,
|
||||||
by_alias=True,
|
return_obj=True,
|
||||||
exclude_unset=True
|
by_alias=True,
|
||||||
)
|
exclude_unset=True
|
||||||
|
)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
table_name_update = 'contact'
|
|
||||||
table_name_select = 'v_contact'
|
|
||||||
obj_id = contact_id
|
|
||||||
obj_data_dict = contact.dict(by_alias=False, exclude_unset=True)
|
|
||||||
obj_data_dict['id'] = redis_lookup_id_random(record_id_random=obj_id, table_name=table_name_update)
|
|
||||||
obj_data_dict['id_random'] = contact_id # NOTE: Adding this in so the id_random is NOT updated
|
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(obj_data_dict)
|
|
||||||
obj_data = lookup_id_random_pop(obj_data_dict)
|
|
||||||
base_name = Contact_Base
|
|
||||||
|
|
||||||
if sql_update_result := sql_update(table_name=table_name_update, data=obj_data):
|
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(sql_update_result)
|
|
||||||
#obj_id = sql_update_result
|
|
||||||
obj_id = obj_data_dict['id']
|
|
||||||
else:
|
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(sql_update_result)
|
|
||||||
return mk_resp(data=False, status_code=400)
|
|
||||||
|
|
||||||
if sql_select_result := sql_select(table_name=table_name_select, record_id=obj_id):
|
|
||||||
log.debug(sql_select_result)
|
|
||||||
|
|
||||||
resp_data = base_name(**sql_select_result).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
|
||||||
|
|
||||||
return mk_resp(data=resp_data)
|
|
||||||
else:
|
|
||||||
log.debug(sql_select_result)
|
|
||||||
return mk_resp(data=False, status_code=404)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user