Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

23563 - update review endpoint #3029

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/business.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4649,8 +4649,10 @@ components:
- foreignJurisdiction
- authorization
- nameRequest
- contactPoint
- offices
- parties
- shareStructure
properties:
business:
$ref: '#/components/schemas/Business'
Expand Down Expand Up @@ -4687,7 +4689,6 @@ components:
type: object
required:
- files
- date
properties:
files:
type: array
Expand Down
44 changes: 7 additions & 37 deletions legal-api/src/legal_api/models/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
from __future__ import annotations

from dataclasses import dataclass, field
from datetime import timezone
from enum import auto
from operator import and_
from typing import List

from legal_api.utils.base import BaseEnum
from legal_api.utils.datetime import datetime
from legal_api.utils.legislation_datetime import LegislationDatetime

from .db import db
from .filing import Filing


class ReviewStatus(BaseEnum):
Expand Down Expand Up @@ -85,8 +82,7 @@ def get_review(cls, filing_id) -> Review:
@classmethod
def get_paginated_reviews(cls, review_filter, mapped_sort_by_column):
"""Return filtered, sorted and paginated reviews."""
query = db.session.query(Review, Filing.effective_date). \
join(Filing, Filing.id == Review.filing_id)
query = db.session.query(Review)

if review_filter.start_date:
start_date = datetime.combine(LegislationDatetime.as_utc_timezone_from_legislation_date_str
Expand All @@ -96,16 +92,6 @@ def get_paginated_reviews(cls, review_filter, mapped_sort_by_column):
end_date = datetime.combine(LegislationDatetime.as_utc_timezone_from_legislation_date_str
(review_filter.end_date), datetime.max.time())
query = query.filter(Review.submission_date <= end_date)
if review_filter.start_effective_date:
start_date_fed = datetime.combine(LegislationDatetime.as_utc_timezone_from_legislation_date_str
(review_filter.start_effective_date), datetime.min.time())
query = query.filter(and_(Filing.effective_date > datetime.now(timezone.utc),
Filing.effective_date >= start_date_fed))
if review_filter.end_effective_date:
end_date_fed = datetime.combine(LegislationDatetime.as_utc_timezone_from_legislation_date_str
(review_filter.end_effective_date), datetime.max.time())
query = query.filter(and_(Filing.effective_date > datetime.now(timezone.utc),
Filing.effective_date <= end_date_fed))
if review_filter.nr_number:
query = query.filter(Review.nr_number.ilike(f'%{review_filter.nr_number}%'))
if review_filter.identifier:
Expand All @@ -115,41 +101,27 @@ def get_paginated_reviews(cls, review_filter, mapped_sort_by_column):
if review_filter.status:
query = query.filter(Review.status.in_(review_filter.status))
if review_filter.submitted_sort_by:
column = Filing.__table__.columns[mapped_sort_by_column] if mapped_sort_by_column == 'effective_date'\
else Review.__table__.columns[mapped_sort_by_column]
column = Review.__table__.columns[mapped_sort_by_column]
query = query.order_by(column.desc() if review_filter.submitted_sort_order == 'true' else column.asc())
else:
query = query.order_by(Review.creation_date.asc())

pagination = query.paginate(per_page=review_filter.limit, page=review_filter.page)
results = pagination.items
total_count = pagination.total
result = Review.build_reviews(results)

reviews_list = [
review.json for review in results
]

reviews = {
'reviews': result,
'reviews': reviews_list,
'page': review_filter.page,
'limit': review_filter.limit,
'total': total_count
}
return reviews

@classmethod
def build_reviews(cls, results):
"""Return reviews with appended future effective date."""
result = []

for review, effective_date in results:
future_effective_date = ''
if effective_date > datetime.now(timezone.utc):
future_effective_date = effective_date.isoformat()

result.append({
**review.json,
'futureEffectiveDate': future_effective_date
})
return result

@property
def json(self) -> dict:
"""Return Review as a JSON object."""
Expand All @@ -172,8 +144,6 @@ class ReviewFilter:
status: List[str] = field()
start_date: str = ''
end_date: str = ''
start_effective_date: str = ''
end_effective_date: str = ''
nr_number: str = ''
identifier: str = ''
contact_email: str = ''
Expand Down
4 changes: 0 additions & 4 deletions legal-api/src/legal_api/resources/v2/admin/reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def get_reviews():
review_filter = Review.ReviewFilter(
start_date=request.args.get('startDate', None),
end_date=request.args.get('endDate', None),
start_effective_date=request.args.get('startEffectiveDate', None),
end_effective_date=request.args.get('endEffectiveDate', None),
nr_number=request.args.get('nrNumber', None),
identifier=request.args.get('identifier', None),
contact_email=request.args.get('contactEmail', None),
Expand Down Expand Up @@ -101,8 +99,6 @@ def get_mapped_column(submitted_sort_by):
mapped_column = 'status'
elif submitted_sort_by == 'identifier':
mapped_column = 'identifier'
elif submitted_sort_by == 'futureEffectiveDate':
mapped_column = 'effective_date'
return mapped_column


Expand Down
Loading