Working on the basic SQL select API CRUD and lots of models
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from __future__ import annotations
|
||||
import datetime, redis
|
||||
|
||||
#from datetime import datetime, time, timedelta
|
||||
@@ -6,7 +7,7 @@ from pydantic import BaseModel, EmailStr, Field
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
|
||||
from .log import *
|
||||
from .db_sql import *
|
||||
from .db_sql import sql_select
|
||||
|
||||
|
||||
async def get_token_header(x_token: str = Header(...)):
|
||||
@@ -15,8 +16,9 @@ async def get_token_header(x_token: str = Header(...)):
|
||||
|
||||
|
||||
async def get_account_header(x_account_id: str = Header(...)):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARN, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARN, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
print('get_account_header(): '+x_account_id)
|
||||
|
||||
if len(x_account_id):
|
||||
@@ -117,3 +119,120 @@ def redis_lookup_id_random(record_id_random=None, table_name=None):
|
||||
log.setLevel(logging.ERROR) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.error('We should not be here. Something unexpected happened.')
|
||||
return False # Just in case
|
||||
|
||||
|
||||
# Look up and resolve id_random values to their id
|
||||
# Remove the unneeded *_id_random key from the dict
|
||||
def lookup_id_random_pop(obj_data=None):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if 'account_id_random' in obj_data:
|
||||
obj_data['account_id'] = redis_lookup_id_random(record_id_random=obj_data['account_id_random'], table_name='account')
|
||||
obj_data.pop('account_id_random')
|
||||
|
||||
if 'address_id_random' in obj_data:
|
||||
obj_data['address_id'] = redis_lookup_id_random(record_id_random=obj_data['address_id_random'], table_name='address')
|
||||
obj_data.pop('address_id_random')
|
||||
|
||||
if 'address_location_id_random' in obj_data:
|
||||
obj_data['address_location_id'] = redis_lookup_id_random(record_id_random=obj_data['address_location_id_random'], table_name='address')
|
||||
obj_data.pop('address_location_id_random')
|
||||
|
||||
if 'archive_id_random' in obj_data:
|
||||
obj_data['archive_id'] = redis_lookup_id_random(record_id_random=obj_data['archive_id_random'], table_name='archive')
|
||||
obj_data.pop('archive_id_random')
|
||||
|
||||
if 'contact_id_random' in obj_data:
|
||||
obj_data['contact_id'] = redis_lookup_id_random(record_id_random=obj_data['contact_id_random'], table_name='contact')
|
||||
obj_data.pop('contact_id_random')
|
||||
|
||||
if 'event_id_random' in obj_data:
|
||||
obj_data['event_id'] = redis_lookup_id_random(record_id_random=obj_data.get('event_id_random', None), table_name='event')
|
||||
obj_data.pop('event_id_random')
|
||||
|
||||
if 'event_exhibit_id_random' in obj_data:
|
||||
obj_data['event_exhibit_id'] = redis_lookup_id_random(record_id_random=obj_data.get('event_exhibit_id_random', None), table_name='event_exhibit')
|
||||
obj_data.pop('event_exhibit_id_random')
|
||||
|
||||
if 'hosted_file_id_random' in obj_data:
|
||||
obj_data['hosted_file_id'] = redis_lookup_id_random(record_id_random=obj_data.get('hosted_file_id_random', None), table_name='hosted_file')
|
||||
obj_data.pop('hosted_file_id_random')
|
||||
|
||||
if 'order_id_random' in obj_data:
|
||||
obj_data['order_id'] = redis_lookup_id_random(record_id_random=obj_data.get('order_id_random', None), table_name='order')
|
||||
obj_data.pop('order_id_random')
|
||||
|
||||
if 'order_line_id_random' in obj_data:
|
||||
obj_data['order_line_id'] = redis_lookup_id_random(record_id_random=obj_data.get('order_line_id_random', None), table_name='order_line')
|
||||
obj_data.pop('order_line_id_random')
|
||||
|
||||
if 'order_cart_id_random' in obj_data:
|
||||
obj_data['order_cart_id'] = redis_lookup_id_random(record_id_random=obj_data.get('order_cart_id_random', None), table_name='order_cart')
|
||||
obj_data.pop('order_cart_id_random')
|
||||
|
||||
if 'order_cart_line_id_random' in obj_data:
|
||||
obj_data['order_cart_line_id'] = redis_lookup_id_random(record_id_random=obj_data.get('order_cart_line_id_random', None), table_name='order_cart_line')
|
||||
obj_data.pop('order_cart_line_id_random')
|
||||
|
||||
if 'organization_id_random' in obj_data:
|
||||
obj_data['organization_id'] = redis_lookup_id_random(record_id_random=obj_data.get('organization_id_random', None), table_name='organization')
|
||||
obj_data.pop('organization_id_random')
|
||||
|
||||
if 'person_id_random' in obj_data:
|
||||
obj_data['person_id'] = redis_lookup_id_random(record_id_random=obj_data['person_id_random'], table_name='person')
|
||||
obj_data.pop('person_id_random')
|
||||
|
||||
if 'post_id_random' in obj_data:
|
||||
obj_data['post_id'] = redis_lookup_id_random(record_id_random=obj_data.get('post_id_random', None), table_name='post')
|
||||
obj_data.pop('post_id_random')
|
||||
|
||||
if 'product_id_random' in obj_data:
|
||||
obj_data['product_id'] = redis_lookup_id_random(record_id_random=obj_data['product_id_random'], table_name='product')
|
||||
obj_data.pop('product_id_random')
|
||||
|
||||
if 'user_id_random' in obj_data:
|
||||
obj_data['user_id'] = redis_lookup_id_random(record_id_random=obj_data['user_id_random'], table_name='user')
|
||||
obj_data.pop('user_id_random')
|
||||
|
||||
if 'for_type' in obj_data and 'for_id_random' in obj_data:
|
||||
obj_data['for_id'] = redis_lookup_id_random(record_id_random=obj_data.get('for_id_random', None), table_name=obj_data.get('for_type', None))
|
||||
obj_data.pop('for_id_random')
|
||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(obj_data)
|
||||
elif 'for_id_random' in obj_data:
|
||||
# In case for_id_random was passed without for_type
|
||||
log.warn('for_id_random was passed without for_type')
|
||||
obj_data.pop('for_id_random')
|
||||
|
||||
if 'object_type' in obj_data and 'object_id_random' in obj_data:
|
||||
obj_data['object_id'] = redis_lookup_id_random(record_id_random=obj_data.get('object_id_random', None), table_name=obj_data.get('object_type', None))
|
||||
obj_data.pop('object_id_random')
|
||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(obj_data)
|
||||
elif 'object_id_random' in obj_data:
|
||||
# In case object_id_random was passed without object_type
|
||||
log.warn('object_id_random was passed without object_type')
|
||||
obj_data.pop('object_id_random')
|
||||
|
||||
if 'to_object_type' in obj_data and 'to_object_id_random' in obj_data:
|
||||
obj_data['to_object_id'] = redis_lookup_id_random(record_id_random=obj_data.get('to_object_id_random', None), table_name=obj_data.get('to_object_type', None))
|
||||
obj_data.pop('to_object_id_random')
|
||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(obj_data)
|
||||
elif 'to_object_id_random' in obj_data:
|
||||
# In case to_object_id_random was passed without to_object_type
|
||||
log.warn('to_object_id_random was passed without to_object_type')
|
||||
obj_data.pop('to_object_id_random')
|
||||
|
||||
if 'from_object_type' in obj_data and 'from_object_id_random' in obj_data:
|
||||
obj_data['from_object_id'] = redis_lookup_id_random(record_id_random=obj_data.get('from_object_id_random', None), table_name=obj_data.get('from_object_type', None))
|
||||
obj_data.pop('from_object_id_random')
|
||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(obj_data)
|
||||
elif 'from_object_id_random' in obj_data:
|
||||
# In case from_object_id_random was passed without from_object_type
|
||||
log.warn('from_object_id_random was passed without from_object_type')
|
||||
obj_data.pop('from_object_id_random')
|
||||
|
||||
return obj_data
|
||||
|
||||
Reference in New Issue
Block a user