Skip to content
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

Added endpoint to return lei data from list of leis #20

Merged
merged 15 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/entities/repos/institutions_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ async def get_institution(session: AsyncSession, lei: str) -> FinancialInstituti
return await session.scalar(stmt)


async def get_institutions_from_lei_list(
lchen-2101 marked this conversation as resolved.
Show resolved Hide resolved
session: AsyncSession,
lei_list: List[str]
) -> List[FinancialInstitutionDao]:
async with session.begin():
stmt = (
select(FinancialInstitutionDao)
.options(joinedload(FinancialInstitutionDao.domains))
.filter(FinancialInstitutionDao.lei.in_(lei_list))
)
res = await session.scalars(stmt)
return res.unique().all()


async def upsert_institution(
session: AsyncSession, fi: FinancialInstitutionDto
) -> FinancialInstitutionDao:
Expand Down
13 changes: 13 additions & 0 deletions src/routers/institutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ async def get_institution(
return res


@router.post("/leis", response_model=List[FinancialInstitutionWithDomainsDto])
lchen-2101 marked this conversation as resolved.
Show resolved Hide resolved
@requires("authenticated")
async def get_institutions_from_lei_list(
request: Request,
lei_list: List[str],
session: AsyncSession = Depends(get_session),
):
res = await repo.get_institutions_from_lei_list(session, lei_list)
if not res:
raise HTTPException(HTTPStatus.NOT_FOUND, f"Leis in {lei_list} not found.")
return res


@router.post("/{lei}/domains/", response_model=List[FinancialInsitutionDomainDto])
@requires(["query-groups", "manage-users"])
async def add_domains(
Expand Down