-
Notifications
You must be signed in to change notification settings - Fork 27
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
mikehgrantsgov
merged 35 commits into
main
from
mikehgrantsgov/3057-add-agencies-listing-api
Dec 5, 2024
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
c6a8215
Merge
mikehmassgov 259055b
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov
mikehmassgov 9ccc235
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov
mikehmassgov d199fb1
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov
mikehmassgov e8f88b3
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov
mikehmassgov 0af1c0e
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov
mikehmassgov d682c35
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov
mikehmassgov 23e8354
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov
mikehmassgov e5ef23e
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov
mikehmassgov fbc72df
Add agencies API
mikehmassgov ca36923
Clean up
mikehmassgov ff4e004
Clean up / format
mikehmassgov a92e77a
Lint
mikehmassgov 64e756e
Update Dockerfile
mikehmassgov 5463242
Update Dockerfile
mikehmassgov 9b61c2d
Update Dockerfile
mikehmassgov cbec699
Create ERD diagram and Update OpenAPI spec
nava-platform-bot cd2674e
Merge branch 'main' into mikehgrantsgov/3057-add-agencies-listing-api
mikehgrantsgov 14a2560
Fix subsequent test?
mikehmassgov 48f2dc4
Merge branch 'mikehgrantsgov/3057-add-agencies-listing-api' of https:…
mikehmassgov 7596bdc
Clean up
mikehmassgov 19ebcbb
Remove cleanup
mikehmassgov 81498e1
Merge branch 'main' into mikehgrantsgov/3057-add-agencies-listing-api
mikehgrantsgov f4961a6
Clean up agencies via ORM
mikehmassgov 07d3c0a
Merge branch 'mikehgrantsgov/3057-add-agencies-listing-api' of https:…
mikehmassgov 6f217a0
Use class approach
mikehmassgov 021e9a6
Format
mikehmassgov bf36855
Merge branch 'main' into mikehgrantsgov/3057-add-agencies-listing-api
mikehgrantsgov 62996c7
Fix agency code genderation
mikehmassgov 0efa8be
Add description / filter out test agencies from respose
mikehmassgov 9081f53
Remove is_test_agency from schema
mikehmassgov 9f4a40a
Create ERD diagram and Update OpenAPI spec
nava-platform-bot f70495e
Update schema and add test for top level agencies
mikehmassgov b79eb35
Merge branch 'mikehgrantsgov/3057-add-agencies-listing-api' of https:…
mikehmassgov 1a8cdc8
Create ERD diagram and Update OpenAPI spec
nava-platform-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from src.api.agencies_v1.agency_blueprint import agency_blueprint | ||
|
||
# import agency_routes module to register the API routes on the blueprint | ||
import src.api.agencies_v1.agency_routes # noqa: F401 E402 isort:skip | ||
|
||
__all__ = ["agency_blueprint"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from apiflask import APIBlueprint | ||
|
||
agency_blueprint = APIBlueprint( | ||
"agency_v1", | ||
__name__, | ||
tag="Agency v1", | ||
cli_group="agency_v1", | ||
url_prefix="/v1", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import logging | ||
|
||
import src.adapters.db as db | ||
import src.adapters.db.flask_db as flask_db | ||
import src.api.agencies_v1.agency_schema as agency_schema | ||
import src.api.response as response | ||
from src.api.agencies_v1.agency_blueprint import agency_blueprint | ||
from src.auth.api_key_auth import api_key_auth | ||
from src.logging.flask_logger import add_extra_data_to_current_request_logs | ||
from src.services.agencies_v1.get_agencies import AgencyListParams, get_agencies | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
examples = { | ||
"example1": { | ||
"summary": "No filters", | ||
"value": { | ||
"pagination": { | ||
"order_by": "created_at", | ||
"page_offset": 1, | ||
"page_size": 25, | ||
"sort_direction": "descending", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
|
||
@agency_blueprint.post("/agencies") | ||
@agency_blueprint.input( | ||
agency_schema.AgencyListRequestSchema, | ||
arg_name="raw_list_params", | ||
examples=examples, | ||
) | ||
@agency_blueprint.output(agency_schema.AgencyListResponseSchema) | ||
@agency_blueprint.auth_required(api_key_auth) | ||
@flask_db.with_db_session() | ||
def agencies_get(db_session: db.Session, raw_list_params: dict) -> response.ApiResponse: | ||
list_params: AgencyListParams = AgencyListParams.model_validate(raw_list_params) | ||
|
||
# Call service with params to get results | ||
with db_session.begin(): | ||
results, pagination_info = get_agencies(db_session, list_params) | ||
|
||
add_extra_data_to_current_request_logs( | ||
{ | ||
"response.pagination.total_pages": pagination_info.total_pages, | ||
"response.pagination.total_records": pagination_info.total_records, | ||
} | ||
) | ||
logger.info("Successfully fetched agencies") | ||
|
||
# Serialize results | ||
return response.ApiResponse(message="Success", data=results, pagination_info=pagination_info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from src.api.schemas.extension import Schema, fields | ||
from src.api.schemas.response_schema import AbstractResponseSchema, PaginationMixinSchema | ||
from src.constants.lookup_constants import AgencyDownloadFileType | ||
from src.pagination.pagination_schema import generate_pagination_schema | ||
|
||
|
||
class AgencyFilterV1Schema(Schema): | ||
agency_id = fields.Integer() | ||
|
||
|
||
class AgencyListRequestSchema(Schema): | ||
filters = fields.Nested(AgencyFilterV1Schema()) | ||
pagination = fields.Nested( | ||
generate_pagination_schema( | ||
"AgencyPaginationV1Schema", | ||
["created_at"], | ||
), | ||
required=True, | ||
) | ||
|
||
|
||
class AgencyContactInfoSchema(Schema): | ||
"""Schema for agency contact information""" | ||
|
||
contact_name = fields.String(metadata={"description": "Full name of the agency contact person"}) | ||
address_line_1 = fields.String(metadata={"description": "Primary street address of the agency"}) | ||
address_line_2 = fields.String( | ||
allow_none=True, | ||
metadata={"description": "Additional address information (suite, unit, etc.)"}, | ||
) | ||
city = fields.String(metadata={"description": "City where the agency is located"}) | ||
state = fields.String(metadata={"description": "State where the agency is located"}) | ||
zip_code = fields.String(metadata={"description": "Postal code for the agency address"}) | ||
phone_number = fields.String(metadata={"description": "Contact phone number for the agency"}) | ||
primary_email = fields.String( | ||
metadata={"description": "Main email address for agency communications"} | ||
) | ||
secondary_email = fields.String( | ||
allow_none=True, | ||
metadata={"description": "Alternative email address for agency communications"}, | ||
) | ||
|
||
|
||
class AgencyResponseSchema(Schema): | ||
"""Schema for agency response""" | ||
|
||
agency_id = fields.Integer() | ||
agency_name = fields.String() | ||
agency_code = fields.String() | ||
sub_agency_code = fields.String(allow_none=True) | ||
assistance_listing_number = fields.String() | ||
agency_submission_notification_setting = fields.String() # Enum value | ||
|
||
top_level_agency = fields.Nested(lambda: AgencyResponseSchema(exclude=("top_level_agency",))) | ||
|
||
# Agency contact info as nested object | ||
agency_contact_info = fields.Nested(AgencyContactInfoSchema, allow_none=True) | ||
|
||
# File types as a list of strings | ||
agency_download_file_types = fields.List( | ||
fields.Enum(AgencyDownloadFileType), | ||
metadata={"description": "List of download file types supported by the agency"}, | ||
) | ||
|
||
# Add timestamps from TimestampMixin | ||
created_at = fields.DateTime() | ||
updated_at = fields.DateTime() | ||
|
||
|
||
class AgencyListResponseSchema(AbstractResponseSchema, PaginationMixinSchema): | ||
data = fields.List( | ||
fields.Nested(AgencyResponseSchema), | ||
metadata={"description": "A list of agency records"}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.