-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from cfpb/35-combine-institution-and-filing-cl…
…eanup-to-single-endpoint Ran linting, updated to have a single /cleanup endpoint
- Loading branch information
Showing
11 changed files
with
257 additions
and
111 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import logging | ||
|
||
from concurrent.futures import ProcessPoolExecutor | ||
from http import HTTPStatus | ||
|
||
from fastapi import Depends, Request, Response, status | ||
from regtech_api_commons.api.exceptions import RegTechHttpException | ||
from regtech_api_commons.api.router_wrapper import Router | ||
from typing import Annotated | ||
|
||
from regtech_cleanup_api.entities.engine.engine import ( | ||
get_filing_session, | ||
get_institution_session, | ||
) | ||
|
||
from sqlalchemy.orm import Session | ||
|
||
from regtech_api_commons.api.dependencies import verify_user_lei_relation | ||
|
||
import regtech_cleanup_api.entities.repos.submission_repo as submission_repo | ||
|
||
from regtech_cleanup_api.routers.institution_cleanup import ( | ||
delete_helper as institution_delete_helper, | ||
) | ||
from regtech_cleanup_api.routers.filing_cleanup import ( | ||
delete_helper as filing_delete_helper, | ||
) | ||
|
||
from regtech_cleanup_api.services.validation import is_valid_cleanup_lei | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def set_institution_db(request: Request, session: Session = Depends(get_institution_session)): | ||
request.state.institution_db_session = session | ||
|
||
|
||
def set_filing_db(request: Request, session: Annotated[Session, Depends(get_filing_session)]): | ||
request.state.filing_db_session = session | ||
|
||
|
||
executor = ProcessPoolExecutor() | ||
router = Router( | ||
dependencies=[ | ||
Depends(set_filing_db), | ||
Depends(set_institution_db), | ||
Depends(verify_user_lei_relation), | ||
] | ||
) | ||
|
||
|
||
@router.delete("/{lei}") | ||
def delete_all_things(request: Request, lei: str): | ||
if not is_valid_cleanup_lei(lei): | ||
raise RegTechHttpException( | ||
HTTPStatus.NOT_ACCEPTABLE, | ||
name="Not Test LEI", | ||
detail=f"{lei} not valid test lei.", | ||
) | ||
else: | ||
institution_delete_helper(lei, request.state.institution_db_session) | ||
|
||
filings = submission_repo.get_filings(request.state.filing_db_session, lei) | ||
for f in filings: | ||
filing_delete_helper(f.lei, f.filing_period, request.state.filing_db_session) | ||
|
||
return Response(status_code=status.HTTP_204_NO_CONTENT) |
Oops, something went wrong.