A lot of code clean up! Also adding in Response everywhere...

This commit is contained in:
Scott Idem
2021-08-10 18:09:34 -04:00
parent 73466456ee
commit d933395a9f
57 changed files with 290 additions and 147 deletions

View File

@@ -1,6 +1,6 @@
import datetime
#from datetime import datetime, time, timedelta
from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, status
from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, Response, status
from pydantic import BaseModel, EmailStr, Field
from typing import Dict, List, Optional, Set, Union
@@ -164,6 +164,7 @@ async def get_obj_li(
exclude: Optional[list] = [],
exclude_unset: Optional[bool] = True,
exclude_none: Optional[bool] = True,
response: Response = Response,
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -243,6 +244,7 @@ async def get_obj(
exclude: Optional[list] = [],
exclude_unset: Optional[bool] = True,
exclude_none: Optional[bool] = True,
response: Response = Response,
):
"""
Simple select object type with an ID:
@@ -309,7 +311,7 @@ async def get_obj(
return mk_resp(data=resp_data) #, details=debug_data)
else:
log.debug(sql_result)
return mk_resp(data=False, status_code=404)
return mk_resp(data=False, status_code=404, response=response)
@router.delete('/{obj_type_l1}/{obj_id}')
@@ -321,6 +323,7 @@ async def delete_obj(
obj_type_l3: str=None,
obj_id: str=None,
x_account_id: str = Header(...),
response: Response = Response,
):
"""
Simple delete object type with an ID:
@@ -389,6 +392,7 @@ def post_obj_template(
exclude: Optional[list] = [],
exclude_unset: Optional[bool] = True,
exclude_none: Optional[bool] = True,
response: Response = Response,
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -416,7 +420,7 @@ def post_obj_template(
return mk_resp(data=resp_data)
else:
log.debug(sql_select_result)
return mk_resp(data=False, status_code=404)
return mk_resp(data=False, status_code=404, response=response)
def patch_obj_template(
@@ -429,6 +433,7 @@ def patch_obj_template(
exclude: Optional[list] = [],
exclude_unset: Optional[bool] = True,
exclude_none: Optional[bool] = True,
response: Response = Response,
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -461,7 +466,7 @@ def patch_obj_template(
return mk_resp(data=resp_data)
else:
log.debug(sql_select_result)
return mk_resp(data=False, status_code=404)
return mk_resp(data=False, status_code=404, response=response)
def get_obj_li_template(
@@ -473,6 +478,7 @@ def get_obj_li_template(
exclude: Optional[list] = [],
exclude_unset: Optional[bool] = True,
exclude_none: Optional[bool] = True,
response: Response = Response,
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -512,6 +518,7 @@ def get_obj_template(
exclude: Optional[list] = [],
exclude_unset: Optional[bool] = True,
exclude_none: Optional[bool] = True,
response: Response = Response,
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -538,12 +545,13 @@ def get_obj_template(
return mk_resp(data=resp_data)
else:
log.debug(sql_result)
return mk_resp(data=False, status_code=404)
return mk_resp(data=False, status_code=404, response=response)
def delete_obj_template(
obj_type: str = Query(None, max_length=50),
obj_id: str = Query(None, max_length=22),
response: Response = Response,
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -562,4 +570,4 @@ def delete_obj_template(
return mk_resp(data=True)
else:
log.debug(sql_result)
return mk_resp(data=False, status_code=404)
return mk_resp(data=False, status_code=404, response=response)