Work on archives
This commit is contained in:
@@ -11,6 +11,8 @@ from app.db_sql import *
|
||||
|
||||
from .api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||
|
||||
from app.methods.archive_methods import load_archive_obj
|
||||
|
||||
from app.models.archive_models import Archive_Base
|
||||
from app.models.response_models import *
|
||||
|
||||
@@ -18,7 +20,7 @@ from app.models.response_models import *
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post('', response_model=Resp_Body_Base)
|
||||
@router.post('/archive', response_model=Resp_Body_Base)
|
||||
async def post_archive_obj(
|
||||
obj: Archive_Base,
|
||||
x_account_id: str = Header(...),
|
||||
@@ -42,7 +44,7 @@ async def post_archive_obj(
|
||||
return result
|
||||
|
||||
|
||||
@router.patch('/{obj_id}', response_model=Resp_Body_Base)
|
||||
@router.patch('/archive/{obj_id}', response_model=Resp_Body_Base)
|
||||
async def patch_archive_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
obj: Archive_Base = None,
|
||||
@@ -70,7 +72,7 @@ async def patch_archive_obj(
|
||||
return result
|
||||
|
||||
|
||||
@router.get('/list', response_model=Resp_Body_Base)
|
||||
@router.get('/archive/list', response_model=Resp_Body_Base)
|
||||
async def get_archive_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),
|
||||
@@ -93,28 +95,70 @@ async def get_archive_obj_li(
|
||||
return result
|
||||
|
||||
|
||||
@router.get('/{obj_id}', response_model=Resp_Body_Base)
|
||||
# ### BEGIN ### API Archive ### get_archive_obj() ###
|
||||
# Working well as of 2021-11-01. Using as a template for other routes.
|
||||
@router.get('/archive/{archive_id}', response_model=Resp_Body_Base)
|
||||
async def get_archive_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
archive_id: str = Query(..., min_length=11, max_length=22),
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
hidden: str = 'not_hidden', # hidden, not_hidden, all
|
||||
# inc_address: bool = False, # Under archive and under contact
|
||||
# inc_contact: bool = False,
|
||||
inc_archive_content_list: bool = False,
|
||||
x_account_id: str = Header(...),
|
||||
limit: int = 500, # For now this covers any included objects or object lists
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
obj_type = 'archive'
|
||||
result = get_obj_template(
|
||||
obj_type=obj_type,
|
||||
obj_id=obj_id,
|
||||
by_alias=True,
|
||||
exclude_unset=True,
|
||||
)
|
||||
return result
|
||||
if archive_id := redis_lookup_id_random(record_id_random=archive_id, table_name='archive'): pass
|
||||
else: return mk_resp(data=None, status_code=404, response=response)
|
||||
|
||||
if archive_obj := load_archive_obj(
|
||||
archive_id = archive_id,
|
||||
enabled = enabled,
|
||||
hidden = hidden,
|
||||
# inc_address = inc_address,
|
||||
# inc_contact = inc_contact,
|
||||
inc_archive_content_list = inc_archive_content_list,
|
||||
limit = limit,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
):
|
||||
pass
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=response) # Bad Request
|
||||
|
||||
return mk_resp(data=archive_obj, response=response)
|
||||
# ### END ### API Archive ### get_archive_obj() ###
|
||||
|
||||
|
||||
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
||||
# @router.get('/archive/{obj_id}', response_model=Resp_Body_Base)
|
||||
# async def get_archive_obj(
|
||||
# obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
# x_account_id: str = Header(...),
|
||||
# by_alias: Optional[bool] = True,
|
||||
# exclude_unset: Optional[bool] = True,
|
||||
# response: Response = Response,
|
||||
# ):
|
||||
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(locals())
|
||||
|
||||
# obj_type = 'archive'
|
||||
# result = get_obj_template(
|
||||
# obj_type=obj_type,
|
||||
# obj_id=obj_id,
|
||||
# by_alias=True,
|
||||
# exclude_unset=True,
|
||||
# )
|
||||
# return result
|
||||
|
||||
|
||||
@router.delete('/archive/{obj_id}', response_model=Resp_Body_Base)
|
||||
async def delete_archive_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
x_account_id: str = Header(...),
|
||||
@@ -128,4 +172,4 @@ async def delete_archive_obj(
|
||||
obj_type=obj_type,
|
||||
obj_id=obj_id,
|
||||
)
|
||||
return result
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user