Skip to content

Commit

Permalink
feat: add lapse application endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yolile committed Nov 28, 2024
1 parent 08a99a6 commit f9ea2d9
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class ApplicationActionType(StrEnum):
OCP_DOWNLOAD_APPLICATION = "OCP_DOWNLOAD_APPLICATION"
FI_START_APPLICATION = "FI_START_APPLICATION"
FI_REQUEST_INFORMATION = "FI_REQUEST_INFORMATION"
FI_LAPSE_APPLICATION = "FI_LAPSE_APPLICATION"
OCP_DOWNLOAD_DOCUMENT = "OCP_DOWNLOAD_DOCUMENT"
APPROVED_APPLICATION = "APPROVED_APPLICATION"
REJECTED_APPLICATION = "REJECTED_APPLICATION"
Expand Down
43 changes: 43 additions & 0 deletions app/routers/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,46 @@ async def previous_contracts(
:raise: HTTPException if the user is not authorized to access the application.
"""
return application.previous_awards(session)


@router.post(
"/applications/{id}/lapse",
tags=[util.Tags.applications],
response_model=models.ApplicationWithRelations,
)
async def lapse_application(
id: int,
user: Annotated[models.User, Depends(dependencies.get_user)],
session: Annotated[Session, Depends(get_db)],
application: Annotated[
models.Application,
Depends(
dependencies.get_scoped_application_as_user(
roles=(models.UserType.FI,),
statuses=(
models.ApplicationStatus.SUBMITTED,
models.ApplicationStatus.STARTED,
),
)
),
],
) -> Any:
"""
:param id: The ID of the application to lapse.
:return: The lapsed application with its associated relations.
:raise: HTTPException if the user is not authorized to lapse the application.
"""
with rollback_on_error(session):
application.status = models.ApplicationStatus.LAPSED
application.application_lapsed_at = datetime.now(application.created_at.tzinfo)

models.ApplicationAction.create(
session,
type=models.ApplicationActionType.FI_LAPSE_APPLICATION,
data=jsonable_encoder(application, exclude_unset=True),
application_id=application.id,
user_id=user.id,
)

session.commit()
return application
2 changes: 1 addition & 1 deletion docs/_static/openapi.json

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions migrations/versions/f4f2b2a76181_add_new_action_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
add new action type
Revision ID: f4f2b2a76181
Revises: 867ef39e878c
Create Date: 2024-11-28 11:55:31.469382
"""

from alembic import op

# revision identifiers, used by Alembic.
revision = "f4f2b2a76181"
down_revision = "867ef39e878c"
branch_labels = None
depends_on = None


def upgrade() -> None:
with op.get_context().autocommit_block():
op.execute(
"""
ALTER TYPE application_action_type ADD VALUE IF NOT EXISTS 'FI_LAPSE_APPLICATION'
"""
)


def downgrade() -> None:
pass
13 changes: 13 additions & 0 deletions tests/routers/test_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,16 @@ def test_get_applications(client, session, admin_header, lender_header, pending_
response = client.post("/applications/access-scheme", json={"uuid": "123-456"})
assert response.status_code == status.HTTP_404_NOT_FOUND
assert response.json() == {"detail": _("Application not found")}


def test_lapse_application(client, session, lender_header, pending_application):
response = client.post(f"/applications/{pending_application.id}/lapse", headers=lender_header)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert response.json() == {"detail": _("Application status should not be %(status)s", status=_("PENDING"))}

pending_application.status = models.ApplicationStatus.SUBMITTED
session.commit()

response = client.post(f"/applications/{pending_application.id}/lapse", headers=lender_header)
assert_ok(response)
assert response.json()["status"] == models.ApplicationStatus.LAPSED

0 comments on commit f9ea2d9

Please sign in to comment.