From 2c4290a4fc478f09cf117582d4f241a30c07318f Mon Sep 17 00:00:00 2001 From: PaulG <144158015+PaulGarewal@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:08:38 -0700 Subject: [PATCH] 21985 Review Endpoint Creation (#2822) * 21985 review endpoint creation * fix: added missing json for review result * review result logic fixes * changed auth to only staff access * updated reviews to admin folder * review endpoint pre unit test addition * lint fix * review fixes for filing link and reviewer in model * removed unit test for reviews for next PR * removed if statement --- legal-api/src/legal_api/models/review.py | 15 +++++++ .../src/legal_api/models/review_result.py | 11 +++++ .../legal_api/resources/v2/admin/__init__.py | 1 + .../legal_api/resources/v2/admin/reviews.py | 43 +++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 legal-api/src/legal_api/resources/v2/admin/reviews.py diff --git a/legal-api/src/legal_api/models/review.py b/legal-api/src/legal_api/models/review.py index 044ecc57fb..e65ff9f4d2 100644 --- a/legal-api/src/legal_api/models/review.py +++ b/legal-api/src/legal_api/models/review.py @@ -75,3 +75,18 @@ def get_review(cls, filing_id) -> Review: filter(Review.filing_id == filing_id). one_or_none()) return review + + @property + def json(self) -> dict: + """Return Review as a JSON object.""" + return { + 'id': self.id, + 'nrNumber': self.nr_number, + 'identifier': self.identifier, + 'completingParty': self.completing_party, + 'status': self.status.name, + 'submissionDate': self.submission_date.isoformat(), + 'creationDate': self.creation_date.isoformat(), + 'filingId': self.filing_id, + 'results': [result.json for result in self.review_results] + } diff --git a/legal-api/src/legal_api/models/review_result.py b/legal-api/src/legal_api/models/review_result.py index d5d380a429..fcbf5f1ad6 100644 --- a/legal-api/src/legal_api/models/review_result.py +++ b/legal-api/src/legal_api/models/review_result.py @@ -69,3 +69,14 @@ def get_last_review_result(cls, review_id) -> ReviewResult: order_by(ReviewResult.creation_date.desc()). first()) return review_result + + @property + def json(self) -> dict: + """Return ReviewResult as a JSON object.""" + return { + 'status': self.status.name, + 'comments': self.comments, + 'reviewer': self.reviewer.display_name, + 'submissionDate': self.submission_date.isoformat() if self.submission_date else None, + 'creationDate': self.creation_date + } diff --git a/legal-api/src/legal_api/resources/v2/admin/__init__.py b/legal-api/src/legal_api/resources/v2/admin/__init__.py index 5eb06c4ab3..333423d184 100644 --- a/legal-api/src/legal_api/resources/v2/admin/__init__.py +++ b/legal-api/src/legal_api/resources/v2/admin/__init__.py @@ -19,6 +19,7 @@ from .bp import bp_admin from .configuration import get_configurations, update_configurations from .dissolution import get_statistics +from .reviews import get_review __all__ = ('bp_admin',) diff --git a/legal-api/src/legal_api/resources/v2/admin/reviews.py b/legal-api/src/legal_api/resources/v2/admin/reviews.py new file mode 100644 index 0000000000..bf87b0e3b5 --- /dev/null +++ b/legal-api/src/legal_api/resources/v2/admin/reviews.py @@ -0,0 +1,43 @@ +# Copyright © 2024 Province of British Columbia +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""API endpoints for retrieving review data.""" +from http import HTTPStatus + +from flask import current_app, jsonify +from flask_cors import cross_origin + +from legal_api.models import Filing, Review, UserRoles +from legal_api.utils.auth import jwt + +from .bp import bp_admin + + +@bp_admin.route('/reviews/', methods=['GET', 'OPTIONS']) +@cross_origin(origin='*') +@jwt.has_one_of_roles([UserRoles.staff]) +def get_review(review_id: int): + """Return specific review.""" + review = Review.find_by_id(review_id) + + if not review: + return jsonify({'message': 'Review not found.'}), HTTPStatus.NOT_FOUND + result = review.json + + filing = Filing.find_by_id(review.filing_id) + base_url = current_app.config.get('LEGAL_API_BASE_URL') + filing_link = f'{base_url}/{filing.temp_reg}/filings/{filing.id}' + + result['filingLink'] = filing_link + + return jsonify(result), HTTPStatus.OK