General clean up

This commit is contained in:
Scott Idem
2021-03-17 20:53:52 +00:00
parent b57e51e8e7
commit 166a2212b9
4 changed files with 41 additions and 17 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
@@ -94,6 +94,7 @@ async def get_order_cart_obj_li(
# Look up is only for account, order, person, or user records
@router.get('/lookup', response_model=Resp_Body_Base)
async def lookup_order_cart_obj(
response: Response,
for_obj_type: Optional[str] = Query(None, min_length=2, max_length=50),
for_obj_id: Optional[Union[int,str]] = None,
inc_order_cart_line_li: Optional[bool] = True,
@@ -166,27 +167,26 @@ async def lookup_order_cart_obj(
return mk_resp(data=data)
else:
log.debug(order_cart_obj_result)
return mk_resp(data=False, status_code=404) # Not Found
return mk_resp(data=False, status_code=404, response=response) # Not Found
@router.get('/{obj_id}', response_model=Resp_Body_Base)
@router.get('/{order_cart_id}', response_model=Resp_Body_Base)
async def get_order_cart_obj(
obj_id: str = Query(..., min_length=1, max_length=22),
order_cart_id: str = Query(..., min_length=1, max_length=22),
inc_order_cart_line_li: bool = False,
inc_order_cart_cfg: bool = False,
x_account_id: str = Header(...),
by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True,
by_alias: bool = True,
exclude_unset: bool = True,
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
obj_type = 'order_cart'
result = get_obj_template(
obj_type=obj_type,
obj_id=obj_id,
by_alias=True,
exclude_unset=True,
)
return result
if order_cart_obj := load_order_cart_obj(order_cart_id=order_cart_id, inc_order_cart_line_li=inc_order_cart_line_li, inc_order_cart_cfg=inc_order_cart_cfg):
data = order_cart_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset)
return mk_resp(data=data)
else:
return mk_resp(data=False, status_code=404) # Not Found
@router.delete('/{obj_id}', response_model=Resp_Body_Base)