Skip to content

Commit

Permalink
Merge pull request #174 from shaangill025/fix_23419
Browse files Browse the repository at this point in the history
Backend: Replace Application ID with Application Number
  • Loading branch information
shaangill025 authored Oct 11, 2024
2 parents 8eaf980 + f0775fc commit b6dc679
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 143 deletions.
2 changes: 1 addition & 1 deletion strr-api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "strr-api"
version = "0.0.12"
version = "0.0.13"
description = ""
authors = ["thorwolpert <thor@wolpert.ca>"]
license = "BSD 3-Clause"
Expand Down
1 change: 0 additions & 1 deletion strr-api/src/strr_api/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ def to_dict(application: Application) -> dict:
application_dict = copy.deepcopy(application.application_json)
if not application_dict.get("header", None):
application_dict["header"] = {}
application_dict["header"]["id"] = application.id
application_dict["header"]["applicationNumber"] = application.application_number
application_dict["header"]["name"] = application.type
application_dict["header"]["paymentToken"] = application.invoice_id
Expand Down
125 changes: 63 additions & 62 deletions strr-api/src/strr_api/resources/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,22 @@ def get_applications():
return exception_response(service_exception)


@bp.route("/<application_id>", methods=("GET",))
@bp.route("/<application_number>", methods=("GET",))
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
@jwt.requires_auth
def get_application_details(application_id):
def get_application_details(application_number):
"""
Get application details
---
tags:
- application
parameters:
- in: path
name: application_id
type: integer
name: application_number
type: string
required: true
description: Application Id
description: Application Number
responses:
200:
description:
Expand All @@ -189,30 +189,30 @@ def get_application_details(application_id):

try:
account_id = request.headers.get("Account-Id", None)
application = ApplicationService.get_application(application_id=application_id, account_id=account_id)
application = ApplicationService.get_application(application_number=application_number, account_id=account_id)
if not application:
return error_response(HTTPStatus.NOT_FOUND, ErrorMessage.APPLICATION_NOT_FOUND.value)
return jsonify(ApplicationService.serialize(application)), HTTPStatus.OK
except AuthException as auth_exception:
return exception_response(auth_exception)


@bp.route("/<application_id>/payment-details", methods=("PUT",))
@bp.route("/<application_number>/payment-details", methods=("PUT",))
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
@jwt.requires_auth
def update_application_payment_details(application_id):
def update_application_payment_details(application_number):
"""
Updates the invoice status of a STRR Application.
---
tags:
- application
parameters:
- in: path
name: application_id
type: integer
name: application_number
type: string
required: true
description: ID of the application
description: Application Number
- in: path
name: invoice_id
type: integer
Expand All @@ -236,7 +236,7 @@ def update_application_payment_details(application_id):
"Account Id is missing.",
HTTPStatus.BAD_REQUEST,
)
application = ApplicationService.get_application(application_id, account_id)
application = ApplicationService.get_application(application_number, account_id)
if not application:
raise AuthException()
invoice_details = strr_pay.get_payment_details_by_invoice_id(
Expand All @@ -250,23 +250,23 @@ def update_application_payment_details(application_id):
return exception_response(auth_exception)


@bp.route("/<application_id>/ltsa", methods=("GET",))
@bp.route("/<application_number>/ltsa", methods=("GET",))
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
@jwt.requires_auth
@jwt.has_one_of_roles([Role.STRR_EXAMINER.value, Role.STRR_INVESTIGATOR.value])
def get_application_ltsa(application_id):
def get_application_ltsa(application_number):
"""
Get application LTSA records
---
tags:
- examiner
parameters:
- in: path
name: application_id
type: integer
name: application_number
type: string
required: true
description: Application Id
description: Application Number
responses:
200:
description:
Expand All @@ -277,10 +277,10 @@ def get_application_ltsa(application_id):
"""

try:
application = ApplicationService.get_application(application_id)
application = ApplicationService.get_application(application_number)
if not application:
return error_response(http_status=HTTPStatus.NOT_FOUND, message=ErrorMessage.APPLICATION_NOT_FOUND.value)

application_id = application.id
records = LtsaService.get_application_ltsa_records(application_id=application_id)
return (
jsonify([LTSARecord.from_db(record).model_dump(mode="json") for record in records]),
Expand All @@ -290,23 +290,23 @@ def get_application_ltsa(application_id):
return exception_response(exception)


@bp.route("/<application_id>/auto-approval-records", methods=("GET",))
@bp.route("/<application_number>/auto-approval-records", methods=("GET",))
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
@jwt.requires_auth
@jwt.has_one_of_roles([Role.STRR_EXAMINER.value, Role.STRR_INVESTIGATOR.value])
def get_application_auto_approval_records(application_id):
def get_application_auto_approval_records(application_number):
"""
Get application auto approval records
---
tags:
- examiner
parameters:
- in: path
name: application_id
type: integer
name: application_number
type: string
required: true
description: Application Id
description: Application Number
responses:
200:
description:
Expand All @@ -317,10 +317,10 @@ def get_application_auto_approval_records(application_id):
"""

try:
application = ApplicationService.get_application(application_id)
application = ApplicationService.get_application(application_number)
if not application:
return error_response(HTTPStatus.NOT_FOUND, ErrorMessage.APPLICATION_NOT_FOUND.value)

application_id = application.id
records = ApprovalService.get_approval_records_for_application(application_id)
return (
jsonify([AutoApprovalRecord.from_db(record).model_dump(mode="json") for record in records]),
Expand All @@ -330,22 +330,22 @@ def get_application_auto_approval_records(application_id):
return exception_response(exception)


@bp.route("/<application_id>/events", methods=("GET",))
@bp.route("/<application_number>/events", methods=("GET",))
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
@jwt.requires_auth
def get_application_events(application_id):
def get_application_events(application_number):
"""
Get application events.
---
tags:
- application
parameters:
- in: path
name: application_id
type: integer
name: application_number
type: string
required: true
description: Application Id
description: Application Number
responses:
200:
description:
Expand All @@ -362,7 +362,8 @@ def get_application_events(application_id):
if UserService.is_strr_staff_or_system():
account_id = None
applicant_visible_events_only = False
application = ApplicationService.get_application(application_id=application_id, account_id=account_id)
application = ApplicationService.get_application(application_number=application_number, account_id=account_id)
application_id = application.id
if not application:
return error_response(HTTPStatus.NOT_FOUND, ErrorMessage.APPLICATION_NOT_FOUND.value)

Expand All @@ -376,23 +377,23 @@ def get_application_events(application_id):
return error_response("ErrorMessage.PROCESSING_ERROR.value", HTTPStatus.INTERNAL_SERVER_ERROR)


@bp.route("/<application_id>/status", methods=("PUT",))
@bp.route("/<application_number>/status", methods=("PUT",))
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
@jwt.requires_auth
@jwt.has_one_of_roles([Role.STRR_EXAMINER.value])
def update_application_status(application_id):
def update_application_status(application_number):
"""
Update application status.
---
tags:
- examiner
parameters:
- in: path
name: application_id
type: integer
name: application_number
type: string
required: true
description: Application ID
description: Application Number
responses:
200:
description:
Expand All @@ -413,7 +414,7 @@ def update_application_status(application_id):
message=ErrorMessage.INVALID_APPLICATION_STATUS.value,
http_status=HTTPStatus.BAD_REQUEST,
)
application = ApplicationService.get_application(application_id)
application = ApplicationService.get_application(application_number)
if not application:
return error_response(http_status=HTTPStatus.NOT_FOUND, message=ErrorMessage.APPLICATION_NOT_FOUND.value)
if application.status in APPLICATION_TERMINAL_STATES:
Expand All @@ -428,22 +429,22 @@ def update_application_status(application_id):
return error_response(ErrorMessage.PROCESSING_ERROR.value, HTTPStatus.INTERNAL_SERVER_ERROR)


@bp.route("/<application_id>/documents", methods=("POST",))
@bp.route("/<application_number>/documents", methods=("POST",))
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
@jwt.requires_auth
def upload_registration_supporting_document(application_id):
def upload_registration_supporting_document(application_number):
"""
Upload a supporting document for a STRR application.
---
tags:
- application
parameters:
- in: path
name: application_id
type: integer
name: application_number
type: string
required: true
description: Application ID
description: Application Number
- name: file
in: formData
type: file
Expand All @@ -469,7 +470,7 @@ def upload_registration_supporting_document(application_id):
file = validate_document_upload(request.files)

# only allow upload for registrations that belong to the user
application = ApplicationService.get_application(application_id=application_id, account_id=account_id)
application = ApplicationService.get_application(application_number=application_number, account_id=account_id)
if not application:
raise AuthException()

Expand All @@ -485,22 +486,22 @@ def upload_registration_supporting_document(application_id):
return exception_response(service_exception)


@bp.route("/<application_id>/documents/<file_key>", methods=("GET",))
@bp.route("/<application_number>/documents/<file_key>", methods=("GET",))
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
@jwt.requires_auth
def get_document(application_id, file_key):
def get_document(application_number, file_key):
"""
Get document.
---
tags:
- application
parameters:
- in: path
name: application_id
type: integer
name: application_number
type: string
required: true
description: Application Id
description: Application Number
- in: path
name: file_key
type: string
Expand All @@ -520,7 +521,7 @@ def get_document(application_id, file_key):
try:
# only allow fetch for applications that belong to the user
account_id = request.headers.get("Account-Id", None)
application = ApplicationService.get_application(application_id=application_id, account_id=account_id)
application = ApplicationService.get_application(application_number=application_number, account_id=account_id)
if not application:
raise AuthException()
application_documents = [
Expand All @@ -544,22 +545,22 @@ def get_document(application_id, file_key):
return exception_response(external_exception)


@bp.route("/<application_id>/documents/<file_key>", methods=("DELETE",))
@bp.route("/<application_number>/documents/<file_key>", methods=("DELETE",))
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
@jwt.requires_auth
def delete_document(application_id, file_key):
def delete_document(application_number, file_key):
"""
Delete document.
---
tags:
- application
parameters:
- in: path
name: application_id
type: integer
name: application_number
type: string
required: true
description: Application Id
description: Application Number
- in: path
name: file_key
type: string
Expand All @@ -579,7 +580,7 @@ def delete_document(application_id, file_key):
try:
# only allow upload for registrations that belong to the user
account_id = request.headers.get("Account-Id", None)
application = ApplicationService.get_application(application_id=application_id, account_id=account_id)
application = ApplicationService.get_application(application_number=application_number, account_id=account_id)
if not application:
raise AuthException()

Expand All @@ -591,22 +592,22 @@ def delete_document(application_id, file_key):
return exception_response(external_exception)


@bp.route("/<application_id>/payment/receipt", methods=("GET",))
@bp.route("/<application_number>/payment/receipt", methods=("GET",))
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
@jwt.requires_auth
def get_payment_receipt(application_id):
def get_payment_receipt(application_number):
"""
Get application payment receipt.
---
tags:
- application
parameters:
- in: path
name: application_id
type: integer
name: application_number
type: string
required: true
description: Application Id
description: Application Number
responses:
200:
description:
Expand All @@ -615,7 +616,7 @@ def get_payment_receipt(application_id):
"""

try:
application = ApplicationService.get_application(application_id=application_id)
application = ApplicationService.get_application(application_number=application_number)
if not application:
raise AuthException()

Expand Down
Loading

0 comments on commit b6dc679

Please sign in to comment.