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

[Issue #3057] Create Agencies API #3065

Merged
merged 35 commits into from
Dec 5, 2024

Conversation

mikehgrantsgov
Copy link
Collaborator

Summary

Fixes #3057

Time to review: 30 mins

Changes proposed

Add agencies API supporting pagination and basic filtering (future requirements around shape TBD)

Context for reviewers

Open question: What should the schema return? Right now we are returning all Agency model fields. Maybe we should make this payload smaller depending on the frontend needs.

Additional information

See attached unit test

@mikehgrantsgov mikehgrantsgov marked this pull request as ready for review December 3, 2024 17:11
mdragon
mdragon previously approved these changes Dec 3, 2024
Copy link
Collaborator

@mdragon mdragon left a comment

Choose a reason for hiding this comment

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

Looks good, think we want to restrict a few of the Agency fields as more internal use only.

Comment on lines 52 to 58
has_system_to_system_certificate = fields.Boolean()
can_view_packages_in_grace_period = fields.Boolean()
is_image_workspace_enabled = fields.Boolean()
is_validation_workspace_enabled = fields.Boolean()

# Optional fields
ldap_group = fields.String(allow_none=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

These seem more internal/private

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. @chouinar do we have conventions to have the requestor specify fields it needs? If not I can restrict the response for now to fields only needed by the FE.

Copy link
Collaborator

Choose a reason for hiding this comment

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

On the agency table there are several fields I marked as "unclear usage" that you can exclude. It is fine if the Marshmallow model has less fields than the DB, they'll just get discarded.

We can always add stuff later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I missed the other question you originally had, there isn't any way to change the fields in the response based on what the requestor asks for, at least not right now. Schemas are strictly defined, at best we could null out a bunch of fields for that

Comment on lines +39 to +40
agency_name = fields.String()
agency_code = fields.String()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think these two are the only real pieces the existing FE use case needs. So not sure if we want to hyper fit that in some sort of AgencyList endpoint. Otherwise I think it's fine to return wider objects.

Comment on lines 52 to 58
has_system_to_system_certificate = fields.Boolean()
can_view_packages_in_grace_period = fields.Boolean()
is_image_workspace_enabled = fields.Boolean()
is_validation_workspace_enabled = fields.Boolean()

# Optional fields
ldap_group = fields.String(allow_none=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

On the agency table there are several fields I marked as "unclear usage" that you can exclude. It is fine if the Marshmallow model has less fields than the DB, they'll just get discarded.

We can always add stuff later.

label = fields.String(allow_none=True)

# Related agency info
top_level_agency_id = fields.Integer(allow_none=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can exclude the ID, although we will need this API to return the top level agency info for the frontend to build a hierarchy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed this but sounds like it should stay, though?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need the ID since that is purely internal, but the frontend would want the top level agency itself - which might be a ticket itself as that requires nesting the schema in itself.

You should be able to do that https://marshmallow.readthedocs.io/en/stable/nesting.html#nesting-a-schema-within-itself

Something like:

class AgencySchema(Schema):
     ...
    top_level_agency = fields.Nested(lambda: AgencySchema(exclude=("top_level_agency",)))

That'll nest it within itself, but only go one layer deep since you will have excluded nesting in the layer down.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I spent some time playing with this and added a test to cover this scenario.

Copy link
Collaborator

@mdragon mdragon left a comment

Choose a reason for hiding this comment

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

Looks good.

@mikehgrantsgov mikehgrantsgov merged commit fbd3544 into main Dec 5, 2024
@mikehgrantsgov mikehgrantsgov deleted the mikehgrantsgov/3057-add-agencies-listing-api branch December 5, 2024 19:16
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.

Add API endpoint for list of agencies
5 participants