A lot of route common params clean up

This commit is contained in:
Scott Idem
2022-01-05 15:22:49 -05:00
parent 9a51e75892
commit a70f931688
5 changed files with 166 additions and 248 deletions

View File

@@ -3,7 +3,7 @@ from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, Resp
from pydantic import BaseModel, EmailStr, Field
from typing import Dict, List, Optional, Set, Union
from app.lib_general import log, logging, secure_hash_string, verify_secure_hash_string
from app.lib_general import log, logging, secure_hash_string, verify_secure_hash_string, common_route_params, Common_Route_Params
from app.config import settings
from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, get_id_random,redis_lookup_id_random
@@ -23,11 +23,8 @@ router = APIRouter()
@router.post('/user', response_model=Resp_Body_Base)
async def post_user_obj(
obj: User_Base,
x_account_id: str = Header(...),
return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -51,11 +48,7 @@ async def post_user_obj_new(
user_obj: User_New_Base,
allow_update: bool = False,
avoid_dup_username: bool = False,
x_account_id: str = Header(...),
return_obj: bool = True,
by_alias: bool = True,
exclude_unset: bool = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -90,15 +83,12 @@ async def post_user_obj_new(
async def user_obj_change_password(
user_id: Union[int,str],
user_obj: User_Base,
x_account_id: Optional[str] = Header(..., ),
return_obj: bool = False,
inc_user_role_list: bool = False,
# inc_contact: bool = False,
# inc_organization: bool = False,
# inc_person: bool = False,
by_alias: bool = True,
exclude_unset: bool = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -152,11 +142,8 @@ async def user_obj_change_password(
async def patch_user_obj(
obj: User_Base,
obj_id: str = Query(..., min_length=11, max_length=22),
x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -181,12 +168,8 @@ async def patch_user_obj(
@router.get('/user/new_auth_key', response_model=Resp_Body_Base)
async def user_new_auth_key(
user_id: Optional[str] = Query(None, min_length=2, max_length=50),
x_account_id: str = Header(...),
return_obj: Optional[bool] = False,
by_alias: bool = True,
exclude_unset: bool = True,
exclude_none: bool = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -231,15 +214,11 @@ async def user_authenticate(
password: Optional[str] = Query(None, min_length=8, max_length=100),
auth_key: Optional[str] = Query(None, min_length=11, max_length=22),
valid_email: Optional[bool] = None,
x_account_id: str = Header(...),
inc_user_role_list: bool = False,
inc_contact: bool = False,
inc_organization: bool = False,
inc_person: bool = False,
by_alias: bool = True,
exclude_unset: bool = True,
exclude_none: bool = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -402,11 +381,8 @@ async def user_verify_password(
# user_id: Optional[str] = Query(None, min_length=11, max_length=22),
# username: Optional[str] = Query(None, min_length=3, max_length=50),
# password: Optional[str] = Query(None, min_length=8, max_length=50),
x_account_id: Optional[str] = Header(..., ),
return_obj: bool = False,
by_alias: bool = True,
exclude_unset: bool = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -492,17 +468,12 @@ async def user_verify_password(
@router.get('/account/{account_id}/user/list', response_model=Resp_Body_Base)
async def get_account_user_obj_li(
account_id: str = Query(..., min_length=11, max_length=22),
limit: int = 500, # For now this covers any included objects or object lists
enabled: str = 'enabled', # For now this covers any included objects or object lists
hidden: str = 'not_hidden', # hidden, not_hidden, all
inc_address: bool = False, # Priority l1
inc_contact: bool = False, # Priority l1
inc_person: bool = False, # Priority l1
inc_user_role_list: bool = False, # Priority l1
x_account_id: str = Header(...),
by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -551,10 +522,7 @@ async def get_account_user_obj_li(
async def get_user_obj_li(
for_obj_type: Optional[str] = Query(None, min_length=2, max_length=50),
for_obj_id: Optional[str] = Query(None, min_length=1, max_length=22),
x_account_id: str = Header(...),
by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -575,14 +543,11 @@ async def get_user_obj_li(
async def lookup_user_obj(
for_obj_id: Union[int,str],
for_obj_type: str = Query(..., min_length=2, max_length=50),
x_account_id: str = Header(...),
inc_user_role_list: bool = False,
inc_contact: bool = False,
inc_organization: bool = False,
inc_person: bool = False,
by_alias: bool = True,
exclude_unset: bool = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -653,16 +618,11 @@ async def lookup_user_obj(
async def lookup_email(
account_id: Union[int,str],
email: str = Query(..., min_length=2, max_length=50),
x_account_id: str = Header(...),
inc_user_role_list: bool = False,
inc_contact: bool = False,
inc_organization: bool = False,
inc_person: bool = False,
enabled: str = 'enabled', # enabled, disabled, all
limit: int = 1,
by_alias: bool = True,
exclude_unset: bool = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -753,15 +713,12 @@ async def lookup_email(
async def lookup_username(
account_id: Union[int,str],
username: str = Query(..., min_length=2, max_length=50),
x_account_id: str = Header(...),
inc_address: bool = False,
inc_contact: bool = False,
inc_organization: bool = False,
inc_person: bool = False,
inc_user_role_list: bool = False,
by_alias: bool = True,
exclude_unset: bool = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -831,11 +788,8 @@ async def lookup_username(
async def email_auth_key_url(
user_id: Optional[str] = Query(None, min_length=11, max_length=22),
root_url: Optional[str] = Query(None, min_length=10, max_length=100), # Absolute min = 7
x_account_id: Optional[str] = Header(..., ),
return_obj: bool = False,
by_alias: bool = True,
exclude_unset: bool = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -865,8 +819,6 @@ async def email_auth_key_url(
@router.get('/user/{user_id}', response_model=Resp_Body_Base)
async def get_user_obj(
user_id: str = Query(..., min_length=11, max_length=22),
limit: int = 500, # For now this covers any included objects or object lists
enabled: str = 'enabled', # For now this covers any included objects or object lists
inc_address: bool = False, # Priority l1
# inc_archive_list: bool = False, # Priority l3
inc_contact: bool = False, # Priority l1
@@ -886,10 +838,7 @@ async def get_user_obj(
inc_post_list: bool = False, # Priority l2
inc_post_comment_list: bool = False, # Priority l3
inc_user_role_list: bool = False, # Priority l1
x_account_id: str = Header(...),
by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True,
response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -935,8 +884,8 @@ async def get_user_obj(
# @router.get('/user/{user_id}/order_list', response_model=Resp_Body_Base)
# async def get_user_obj_order_list(
# user_id: str = Query(..., min_length=1, max_length=22),
# limit: int = 500, # For now this covers any included objects or object lists
# enabled: str = 'enabled', # For now this covers any included objects or object lists
#
#
# from_datetime: datetime.datetime = None,
# to_datetime: datetime.datetime = None,
# # inc_address: bool = False,
@@ -947,7 +896,7 @@ async def get_user_obj(
# # inc_person: bool = False,
# # inc_order_list: bool = False,
# # inc_order_cart_list: bool = False,
# x_account_id: str = Header(...),
#
# by_alias: Optional[bool] = True,
# exclude_unset: Optional[bool] = True,
# response: Response = Response,
@@ -999,9 +948,8 @@ async def get_user_obj(
@router.delete('/user/{obj_id}', response_model=Resp_Body_Base)
async def delete_user_obj(
obj_id: str = Query(..., min_length=1, max_length=22),
x_account_id: str = Header(...),
response: Response = Response,
obj_id: str = Query(..., min_length=11, max_length=22),
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())