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

Chore: facility review fixes #2223

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open

Conversation

dleard
Copy link
Contributor

@dleard dleard commented Sep 19, 2024

There were some errors in how facility_id was being applied.
It was being treated as a numeric where it is a UUID value, which had some cascading effects.
This PR should fix that up.
Also cleaned up the API a little bit by splitting out facility-report API/service stuff into its own directory & added some tests.

Easiest way to test this:

  • Go to dashboard & create a report for Operation 3
  • go to /reporting/reports/3/facilities/f486f2fb-62ed-438d-bb3e-0819b51e3aff/review (the facility ID associated with operation 3)
  • There should be data in the form fields
  • change some data & save
  • reload the page
  • see the data has changed

@dleard dleard marked this pull request as ready for review September 19, 2024 19:33


@router.get(
"/report-version/{version_id}/facility-report/{facility_id}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 👌

Copy link
Contributor

@pbastia pbastia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! 🥇 🥇 Just a couple of nitpicks

request: HttpRequest, version_id: int, facility_id: UUID
) -> Tuple[Literal[200], Optional[FacilityReportOut]]:
facility_report = FacilityReportService.get_facility_report_by_version_and_id(version_id, facility_id)
activity_ids = FacilityReportService.get_activity_ids_for_facility(version_id, facility_id) or []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The service already returns an empty list if none are found

Suggested change
activity_ids = FacilityReportService.get_activity_ids_for_facility(version_id, facility_id) or []
activity_ids = FacilityReportService.get_activity_ids_for_facility(version_id, facility_id)

facility_type=facility_report.facility_type,
facility_bcghgid=facility_report.facility_bcghgid,
activities=list(facility_report.activities.values_list('id', flat=True)),
products=list(facility_report.products.values_list('id', flat=True)) or [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
products=list(facility_report.products.values_list('id', flat=True)) or [],
products=list(facility_report.products.values_list('id', flat=True)),

Comment on lines +37 to +47
def facility_report_baker(**props) -> FacilityReport:
if "report_version" not in props and "report_version_id" not in props:
props["report_version"] = report_version_baker()

if "facility" not in props and "facility_id" not in props:
props["facility"] = facility_baker()

fr = baker.make(FacilityReport, **props)

return fr

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a recipe now :D

return list(facility_report.activities.values_list('id', flat=True))

@classmethod
def get_facility_report_form_data(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method is not a service method, it's just something to build API response data within the API layer. I'd put it in the api/facility_report.py file directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants