Working on journal related
This commit is contained in:
@@ -151,7 +151,7 @@ app.include_router(
|
|||||||
)
|
)
|
||||||
app.include_router(
|
app.include_router(
|
||||||
journal_entry.router,
|
journal_entry.router,
|
||||||
prefix='/journal/entry',
|
# prefix='/journal/entry',
|
||||||
tags=['Journal Entry'],
|
tags=['Journal Entry'],
|
||||||
)
|
)
|
||||||
app.include_router(
|
app.include_router(
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, v
|
|||||||
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
||||||
from app.lib_general import log, logging
|
from app.lib_general import log, logging
|
||||||
|
|
||||||
# from app.methods.journal_methods import load_journal_entry_obj
|
|
||||||
|
|
||||||
from app.models.journal_entry_models import Journal_Entry_Base
|
from app.models.journal_entry_models import Journal_Entry_Base
|
||||||
|
|
||||||
|
|
||||||
@@ -43,10 +41,7 @@ def load_journal_entry_obj(
|
|||||||
by_alias: bool = True,
|
by_alias: bool = True,
|
||||||
exclude_unset: bool = True,
|
exclude_unset: bool = True,
|
||||||
model_as_dict: bool = False,
|
model_as_dict: bool = False,
|
||||||
enabled: str = 'enabled', # enabled, disabled, all
|
# enabled: str = 'enabled', # enabled, disabled, all
|
||||||
inc_journal_entry_list: bool = False,
|
|
||||||
inc_person: bool = False,
|
|
||||||
inc_user: bool = False,
|
|
||||||
) -> Journal_Entry_Base|bool:
|
) -> Journal_Entry_Base|bool:
|
||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
@@ -105,20 +100,19 @@ def update_journal_entry_obj(
|
|||||||
|
|
||||||
# ### BEGIN ### API Journal Entry Methods ### get_journal_entry_rec_list() ###
|
# ### BEGIN ### API Journal Entry Methods ### get_journal_entry_rec_list() ###
|
||||||
def get_journal_entry_rec_list(
|
def get_journal_entry_rec_list(
|
||||||
for_obj_type: str,
|
journal_id: str,
|
||||||
for_obj_id: str,
|
|
||||||
limit: int = 1000,
|
limit: int = 1000,
|
||||||
enabled: str = 'enabled', # enabled, disabled, all
|
enabled: str = 'enabled', # enabled, disabled, all
|
||||||
) -> list|bool:
|
) -> list|bool:
|
||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
if for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name=for_obj_type): pass
|
if journal_id := redis_lookup_id_random(record_id_random=journal_id, table_name='journal'): pass
|
||||||
else: return False
|
else: return False
|
||||||
data = {}
|
data = {}
|
||||||
data[f'{for_obj_type}_id'] = for_obj_id
|
data['journal_id'] = journal_id
|
||||||
# data['for_obj_type'] = for_obj_type
|
|
||||||
sql_obj_type_id = f'`tbl`.{for_obj_type}_id = :{for_obj_type}_id'
|
sql_journal_id = f'`tbl`.journal_id = :journal_id'
|
||||||
|
|
||||||
if enabled in ['enabled', 'disabled', 'all']:
|
if enabled in ['enabled', 'disabled', 'all']:
|
||||||
if enabled == 'enabled':
|
if enabled == 'enabled':
|
||||||
@@ -140,7 +134,7 @@ def get_journal_entry_rec_list(
|
|||||||
SELECT `tbl`.id AS 'journal_entry_id', `tbl`.id_random AS 'journal_entry_id_random'
|
SELECT `tbl`.id AS 'journal_entry_id', `tbl`.id_random AS 'journal_entry_id_random'
|
||||||
FROM `journal_entry` AS `tbl`
|
FROM `journal_entry` AS `tbl`
|
||||||
WHERE
|
WHERE
|
||||||
{sql_obj_type_id}
|
{sql_journal_id}
|
||||||
{sql_enabled}
|
{sql_enabled}
|
||||||
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
|
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
|
||||||
{sql_limit};
|
{sql_limit};
|
||||||
|
|||||||
@@ -74,8 +74,7 @@ def load_journal_obj(
|
|||||||
# Updated 2021-06-18
|
# Updated 2021-06-18
|
||||||
if inc_journal_entry_list:
|
if inc_journal_entry_list:
|
||||||
if journal_entry_rec_list_result := get_journal_entry_rec_list(
|
if journal_entry_rec_list_result := get_journal_entry_rec_list(
|
||||||
for_obj_type = 'journal',
|
journal_id = journal_id,
|
||||||
for_obj_id = journal_id,
|
|
||||||
limit = limit,
|
limit = limit,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
):
|
):
|
||||||
@@ -89,8 +88,6 @@ def load_journal_obj(
|
|||||||
exclude_unset = exclude_unset,
|
exclude_unset = exclude_unset,
|
||||||
model_as_dict = model_as_dict,
|
model_as_dict = model_as_dict,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
inc_person = inc_person,
|
|
||||||
inc_user = inc_user,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
journal_obj.journal_entry_list = journal_entry_result_list
|
journal_obj.journal_entry_list = journal_entry_result_list
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ class Journal_Entry_Base(BaseModel):
|
|||||||
alias = 'journal_entry_id'
|
alias = 'journal_entry_id'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
journal_id_random: Optional[str]
|
||||||
|
journal_id: Optional[int]
|
||||||
|
|
||||||
title: Optional[str]
|
title: Optional[str]
|
||||||
summary: Optional[str]
|
summary: Optional[str]
|
||||||
content: Optional[str]
|
content: Optional[str]
|
||||||
@@ -32,6 +35,9 @@ class Journal_Entry_Base(BaseModel):
|
|||||||
personal: Optional[bool] = True
|
personal: Optional[bool] = True
|
||||||
professional: Optional[bool] = False
|
professional: Optional[bool] = False
|
||||||
|
|
||||||
|
archive_on: Optional[datetime.datetime]
|
||||||
|
archive: Optional[bool]
|
||||||
|
|
||||||
enable: Optional[bool]
|
enable: Optional[bool]
|
||||||
hide: Optional[bool]
|
hide: Optional[bool]
|
||||||
priority: Optional[bool]
|
priority: Optional[bool]
|
||||||
@@ -54,6 +60,15 @@ class Journal_Entry_Base(BaseModel):
|
|||||||
return redis_lookup_id_random(record_id_random=values['id_random'], table_name='journal_entry')
|
return redis_lookup_id_random(record_id_random=values['id_random'], table_name='journal_entry')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@validator('journal_id', always=True)
|
||||||
|
def journal_id_lookup(cls, v, values, **kwargs):
|
||||||
|
log.setLevel(logging.WARNING)
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if values['journal_id_random']:
|
||||||
|
return redis_lookup_id_random(record_id_random=values['journal_id_random'], table_name='journal')
|
||||||
|
return None
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
underscore_attrs_are_private = True
|
underscore_attrs_are_private = True
|
||||||
fields = base_fields
|
fields = base_fields
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ class Post_Comment_Base(BaseModel):
|
|||||||
id: Optional[int] = Field(
|
id: Optional[int] = Field(
|
||||||
#alias = 'post_comment_id'
|
#alias = 'post_comment_id'
|
||||||
)
|
)
|
||||||
|
|
||||||
post_id_random: Optional[str]
|
post_id_random: Optional[str]
|
||||||
post_id: Optional[int]
|
post_id: Optional[int]
|
||||||
|
|
||||||
user_id_random: Optional[str]
|
user_id_random: Optional[str]
|
||||||
user_id: Optional[int]
|
user_id: Optional[int]
|
||||||
|
|
||||||
|
|||||||
@@ -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.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.journal_entry_models import Journal_Entry_Base
|
||||||
from app.models.response_models import *
|
from app.models.response_models import *
|
||||||
|
|
||||||
@@ -17,7 +19,7 @@ from app.models.response_models import *
|
|||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.post('', response_model=Resp_Body_Base)
|
@router.post('/journal/entry', response_model=Resp_Body_Base)
|
||||||
async def post_journal_entry_obj(
|
async def post_journal_entry_obj(
|
||||||
obj: Journal_Entry_Base,
|
obj: Journal_Entry_Base,
|
||||||
x_account_id: str = Header(...),
|
x_account_id: str = Header(...),
|
||||||
@@ -40,7 +42,7 @@ async def post_journal_entry_obj(
|
|||||||
return result
|
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(
|
async def patch_journal_entry_obj(
|
||||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||||
obj: Journal_Entry_Base = None,
|
obj: Journal_Entry_Base = None,
|
||||||
@@ -67,7 +69,7 @@ async def patch_journal_entry_obj(
|
|||||||
return result
|
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(
|
async def get_journal_entry_obj_li(
|
||||||
for_obj_type: Optional[str] = Query(None, min_length=2, max_length=50),
|
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),
|
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)
|
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(
|
async def get_journal_entry_obj(
|
||||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||||
x_account_id: str = Header(...),
|
x_account_id: str = Header(...),
|
||||||
@@ -144,7 +146,60 @@ async def get_journal_entry_obj(
|
|||||||
return result
|
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(
|
async def delete_journal_entry_obj(
|
||||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||||
x_account_id: str = Header(...),
|
x_account_id: str = Header(...),
|
||||||
|
|||||||
Reference in New Issue
Block a user