Skip to content

Commit

Permalink
21985 Review Endpoint Creation (bcgov#2822)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
PaulGarewal authored Jul 12, 2024
1 parent b33b3df commit 2c4290a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
15 changes: 15 additions & 0 deletions legal-api/src/legal_api/models/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
11 changes: 11 additions & 0 deletions legal-api/src/legal_api/models/review_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions legal-api/src/legal_api/resources/v2/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',)
43 changes: 43 additions & 0 deletions legal-api/src/legal_api/resources/v2/admin/reviews.py
Original file line number Diff line number Diff line change
@@ -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/<int:review_id>', 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

0 comments on commit 2c4290a

Please sign in to comment.