-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
69 add endpoints to retrieve from look up data tables #74
69 add endpoints to retrieve from look up data tables #74
Conversation
…ndpoint Adds endpoints for getting address-states and regulators Adds institution repo get_ functions for the above Let commented out code in for specific Dtos in case the general approach isn't desired
Coverage reportThe coverage rate went from
Diff Coverage details (click to unfold)src/entities/models/init.py
src/entities/models/dao.py
src/entities/models/dto.py
src/entities/repos/institutions_repo.py
src/entities/repos/repo_utils.py
src/routers/institutions.py
|
async with session.begin(): | ||
stmt = select(SBLInstitutionTypeDao) | ||
res = await session.scalars(stmt) | ||
return res.all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's abstract this portion out, since it's repeated across all of the lookups
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or better yet, just have something like get_look_up(session..., T) -> List[T]
or something like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a repo_utiils with the following
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from typing import List, TypeVar
T = TypeVar("T")
async def query_type(session: AsyncSession, type: T) -> List[T]:
async with session.begin():
stmt = select(type)
res = await session.scalars(stmt)
return res.all()
I thought about putting that directly in the institution_repo and having the routers call it, but as it stands the routers don't "know" about DAOs, just DTOs, so I kept it separate. And the institution_repo now has:
async def get_sbl_types(session: AsyncSession) -> List[SBLInstitutionTypeDao]:
return await query_type(session, SBLInstitutionTypeDao)
async def get_hmda_types(session: AsyncSession) -> List[HMDAInstitutionTypeDao]:
return await query_type(session, HMDAInstitutionTypeDao)
async def get_address_states(session: AsyncSession) -> List[AddressStateDao]:
return await query_type(session, AddressStateDao)
async def get_federal_regulators(session: AsyncSession) -> List[FederalRegulatorDao]:
return await query_type(session, FederalRegulatorDao)
which again is somewhat repetitive, but less so than before.
@@ -45,6 +49,34 @@ async def get_institution(session: AsyncSession, lei: str) -> FinancialInstituti | |||
return await session.scalar(stmt) | |||
|
|||
|
|||
async def get_sbl_types(session: AsyncSession) -> SBLInstitutionTypeDao: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type should be a collection, shouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, updated all these funcs to return List[type]
src/routers/institutions.py
Outdated
if type == "sbl": | ||
return await repo.get_sbl_types(request.state.db_session) | ||
else: | ||
return await repo.get_hmda_types(request.state.db_session) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's be explicit with hmda as well, and throw invalid arg exception when neither matches
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I see, the Literal
would take care of that, in that case I'd still like hmda to be explicit, so maybe use match
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to
match type:
case "sbl":
return await repo.get_sbl_types(request.state.db_session)
case "hmda":
return await repo.get_hmda_types(request.state.db_session)
src/entities/models/dto.py
Outdated
class HMDAInstitutionTypeDto(InstitutionTypeDto): | ||
pass | ||
|
||
|
||
class SBLInstitutionTypeDto(SBLInstitutionTypeBase): | ||
name: str | ||
|
||
class Config: | ||
from_attributes = True | ||
class SBLInstitutionTypeDto(InstitutionTypeDto): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now looking at it, just one dto would work for both, so we can completely remove the distinct ones, at least until the need arises when differences come up later. we can probably also update the dao to have one base dao, and the two specific ones inherit from that, and only change the __tablename__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed commented out DTO references. Added a InstitutionTypeMixin that the HMDA and SBL Inst. Types inherit. Couldn't see a cleaner way to add inheritance here.
Removed commented out code Added a repo_utils with a func that contains a genericized query Added an InstitutionTypeMixin to contain duplicated fields between HMDA and SBL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Closes #69
Added institutions/address-states, institutions/regulators, and institutions/types/{type} endpoints
Went with a 'generic' InstitutionTypeDTO (since both sbl and hmda tables just have id and name). The /types/ endpoint uses a type Literal to limit the accepted types to sbl or hmda. It then queries the specific Dao type. If this approach isn't desired I can break that GET into two separate types/sbl and types/hmda endpoints that return the specific DTO type.
Updated pytests to test these endpoints and the corresponding get_* functions added to the institution repo.