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 #3448] Create API endpoint for POST /users/:userID/save-searches #3472

Merged
merged 20 commits into from
Jan 13, 2025

Conversation

mikehgrantsgov
Copy link
Collaborator

Summary

Fixes #3448

Time to review: 15 mins

Changes proposed

Add POST endpoint to create a saved search including routes and schemas.
Add supporting tests.

Context for reviewers

Supports the saved search requirements.

Additional information

See attached unit tests.

Comment on lines 97 to 103
search_query = fields.Dict(
required=True,
metadata={
"description": "The search query parameters to save",
"example": {"keywords": "search", "location": "Foo, Bar"},
},
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we have this be the actual schema we use in the search endpoint? Just to make sure it's valid.

Also want to make sure the JSON serialization works with a full search request object for things like enums and dates.

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 added something to the test using get_search_request(). Something like this you have in mind?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was thinking we would do search_query = fields.Nested(OpportunitySearchRequestV1Schema) - that way we can only take in a schema that is valid for search. Anything that isn't a valid search request should be rejected (eg. a user couldn't just pass {"some_field": "whatever"}.)

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 checked in the changes. This makes me wonder if we should also store the version of the search request schema for validation later. If, for example, we want the response to correspond to the schema that was inputted. It would be able to handle schema changes (and we could just output a dict response type validated against the stored schema version in a new db column. Otherwise we would not be able to validate response schema if this OpportunitySearchRequestV1Schema changes.

api/src/api/users/user_routes.py Outdated Show resolved Hide resolved
api/src/api/users/user_routes.py Outdated Show resolved Hide resolved
api/src/api/users/user_routes.py Outdated Show resolved Hide resolved
Comment on lines 97 to 103
search_query = fields.Dict(
required=True,
metadata={
"description": "The search query parameters to save",
"example": {"keywords": "search", "location": "Foo, Bar"},
},
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was thinking we would do search_query = fields.Nested(OpportunitySearchRequestV1Schema) - that way we can only take in a schema that is valid for search. Anything that isn't a valid search request should be rejected (eg. a user couldn't just pass {"some_field": "whatever"}.)

Copy link
Collaborator

@chouinar chouinar left a comment

Choose a reason for hiding this comment

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

Just one small change

Comment on lines 15 to 16
with db_session.begin():
db_session.add(saved_search)
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 begin here since we already began it in the route. Actually, in a lot of cases this would error with an "already started transaction error", guessing that didn't happen because you hadn't done any DB operations yet.

@mikehgrantsgov mikehgrantsgov merged commit 0968357 into main Jan 13, 2025
2 checks passed
@mikehgrantsgov mikehgrantsgov deleted the mikehgrantsgov/3448-create-save-search-endpoint branch January 13, 2025 17:24
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.

Create API endpoint for POST /users/:userID/save-searches
3 participants