Working on journal related
This commit is contained in:
@@ -10,6 +10,8 @@ from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select,
|
||||
|
||||
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||
|
||||
from app.methods.journal_entry_methods import get_journal_entry_rec_list, load_journal_entry_obj
|
||||
|
||||
from app.models.journal_entry_models import Journal_Entry_Base
|
||||
from app.models.response_models import *
|
||||
|
||||
@@ -17,7 +19,7 @@ from app.models.response_models import *
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post('', response_model=Resp_Body_Base)
|
||||
@router.post('/journal/entry', response_model=Resp_Body_Base)
|
||||
async def post_journal_entry_obj(
|
||||
obj: Journal_Entry_Base,
|
||||
x_account_id: str = Header(...),
|
||||
@@ -40,7 +42,7 @@ async def post_journal_entry_obj(
|
||||
return result
|
||||
|
||||
|
||||
@router.patch('/{obj_id}', response_model=Resp_Body_Base)
|
||||
@router.patch('/journal/entry/{obj_id}', response_model=Resp_Body_Base)
|
||||
async def patch_journal_entry_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
obj: Journal_Entry_Base = None,
|
||||
@@ -67,7 +69,7 @@ async def patch_journal_entry_obj(
|
||||
return result
|
||||
|
||||
|
||||
@router.get('/list', response_model=Resp_Body_Base)
|
||||
@router.get('/journal/entry/list', response_model=Resp_Body_Base)
|
||||
async def get_journal_entry_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),
|
||||
@@ -124,7 +126,7 @@ async def get_journal_entry_obj_li(
|
||||
return mk_resp(data=False, status_code=404)
|
||||
|
||||
|
||||
@router.get('/{obj_id}', response_model=Resp_Body_Base)
|
||||
@router.get('/journal/entry/{obj_id}', response_model=Resp_Body_Base)
|
||||
async def get_journal_entry_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
x_account_id: str = Header(...),
|
||||
@@ -144,7 +146,60 @@ async def get_journal_entry_obj(
|
||||
return result
|
||||
|
||||
|
||||
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
||||
# ### BEGIN ### API Post ### get_journal_obj_journal_entry_list() ###
|
||||
# Updated 2021-07-22
|
||||
@router.get('/journal/{journal_id}/entry/list', response_model=Resp_Body_Base)
|
||||
async def get_journal_obj_journal_entry_list(
|
||||
journal_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
|
||||
inc_private: bool = False,
|
||||
inc_public: bool = False,
|
||||
inc_personal: bool = False,
|
||||
inc_professional: bool = False,
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if journal_id := redis_lookup_id_random(record_id_random=journal_id, table_name='journal'): pass
|
||||
else:
|
||||
return mk_resp(data=None, status_code=404)
|
||||
|
||||
response_data = None
|
||||
|
||||
# Updated 2021-07-22
|
||||
if journal_entry_rec_list_result := get_journal_entry_rec_list(
|
||||
journal_id = journal_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
# archived = archived,
|
||||
# archive_on = archive_on,
|
||||
):
|
||||
journal_entry_result_list = []
|
||||
for journal_entry_rec in journal_entry_rec_list_result:
|
||||
if load_journal_entry_result := load_journal_entry_obj(
|
||||
journal_entry_id = journal_entry_rec.get('journal_entry_id', None),
|
||||
limit = limit,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
# enabled = enabled,
|
||||
):
|
||||
journal_entry_result_list.append(load_journal_entry_result)
|
||||
else:
|
||||
journal_entry_result_list.append(None)
|
||||
response_data = journal_entry_result_list
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data)
|
||||
# ### END ### API Post ### get_account_obj_journal_entry_list() ###
|
||||
|
||||
|
||||
@router.delete('/journal/entry/{obj_id}', response_model=Resp_Body_Base)
|
||||
async def delete_journal_entry_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
x_account_id: str = Header(...),
|
||||
|
||||
Reference in New Issue
Block a user