Starting the slow migration to FastAPI...
This commit is contained in:
@@ -7,11 +7,8 @@ from ..lib_general import *
|
||||
from ..log import *
|
||||
from app.config import settings
|
||||
from app.db import *
|
||||
from app.redis import *
|
||||
from .user_models import *
|
||||
|
||||
#import logging
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@@ -66,6 +63,8 @@ async def update_user(id_random: str, user: UserIn, x_account_id: str = Depends(
|
||||
"""
|
||||
Update a user account
|
||||
"""
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.debug(locals())
|
||||
|
||||
user = {}
|
||||
user['id_random'] = id_random
|
||||
@@ -84,6 +83,8 @@ async def delete_user(id_random: str, x_account_id: str = Depends(get_account_he
|
||||
"""
|
||||
Delete a user account
|
||||
"""
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.debug(locals())
|
||||
|
||||
return True
|
||||
return False
|
||||
@@ -91,60 +92,58 @@ async def delete_user(id_random: str, x_account_id: str = Depends(get_account_he
|
||||
|
||||
@router.get('/', response_model=List[UserOut])
|
||||
@router.get('/list_all', response_model=List[UserOut])
|
||||
async def list_users():
|
||||
async def list_users(x_account: str = Depends(get_account_header)):
|
||||
"""
|
||||
Get a list of users
|
||||
"""
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.debug(str(locals().keys())+' | '+str(locals().values()))
|
||||
log.debug(locals())
|
||||
|
||||
#log.setLevel(logging.INFO)
|
||||
#log.info(None)
|
||||
|
||||
log.setLevel(logging.WARNING)
|
||||
|
||||
print('***')
|
||||
log.debug('This is debug') # 10 DEBUG
|
||||
log.info('This is info') # 20 INFO
|
||||
log.warn('This is warn') # 30 WARNING
|
||||
log.warning('This is a warning') # 30 WARNING
|
||||
log.error('This is an error') # 40 ERROR
|
||||
log.exception('This is an exception') # 40 ERROR
|
||||
log.critical('This is critical') # 50 CRITICAL
|
||||
|
||||
|
||||
users = [{'username': 'test.user.1'}, {'username': 'test.user.2'}, {'username': 'Scott.Idem'}]
|
||||
|
||||
|
||||
print('Getting all users...')
|
||||
|
||||
sql = """
|
||||
SELECT *
|
||||
FROM `user`
|
||||
/*WHERE id=1*/
|
||||
"""
|
||||
|
||||
records = sql_select(sql=sql, as_list=True)
|
||||
|
||||
#records = sql_select(table_name='user')
|
||||
|
||||
if x_account['id']:
|
||||
log.info('The x-account-id was given and is not empty...')
|
||||
sql = """
|
||||
SELECT *
|
||||
FROM `user`
|
||||
WHERE account_id = :account_id
|
||||
"""
|
||||
records = sql_select(table_name='user', field_name='account_id', field_value=x_account['id'], as_list=True)
|
||||
elif x_account['id'] is None:
|
||||
log.info('The x-account-id was given, but is empty...')
|
||||
sql = """
|
||||
SELECT *
|
||||
FROM `user`
|
||||
"""
|
||||
records = sql_select(table_name='user', as_list=True)
|
||||
|
||||
if records:
|
||||
print('Got the user list')
|
||||
log.info('Returning a user list...')
|
||||
return records
|
||||
else:
|
||||
print('No user records found')
|
||||
log.info('No user records found...')
|
||||
raise HTTPException(status_code=404)
|
||||
|
||||
|
||||
@router.get('/{username}')
|
||||
async def get_user_username(username: str, x_account_id: str = Header(...)):
|
||||
return {'username': username}
|
||||
async def get_user_username(username: str, x_account: str = Depends(get_account_header)):
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.debug(locals())
|
||||
|
||||
data = {}
|
||||
data['username'] = username
|
||||
|
||||
#@router.get('/me')
|
||||
#async def get_user_current():
|
||||
#user_out: UserOut
|
||||
if x_account['id']:
|
||||
sql = """
|
||||
SELECT *
|
||||
FROM `user`
|
||||
WHERE account_id = :account_id AND username=:username
|
||||
"""
|
||||
data['account_id'] = x_account['id']
|
||||
elif x_account['id'] is None:
|
||||
sql = """
|
||||
SELECT *
|
||||
FROM `user`
|
||||
WHERE (account_id IS NULL OR account_id = "") AND username=:username
|
||||
"""
|
||||
record = sql_select(sql=sql, data=data)
|
||||
|
||||
#return {'username': 'test.user'}
|
||||
return record
|
||||
|
||||
Reference in New Issue
Block a user