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

Basic Search API and Temporary UI #195

Merged
merged 15 commits into from
Oct 23, 2021

Conversation

alexjball
Copy link
Member

@alexjball alexjball commented Oct 19, 2021

Closes #191, #113

  • Loads scraped data into the incidents table. The structure of the scraped data is quite different from the current schema, and not all fields map to fields in the schema, so I added a few columns to store the information. Notably, only a few records from the scraped data list an officer, but most list the associated police department. Many records are also missing timestamps.
  • Adds an incident search route POST /api/v1/incidents/search that supports searching by location keyword, description keyword, and date range. keyword search is strictly a substring search, and there is no geocoding of the location.
  • This does not display the results in a table. Since pagination is done by the server, we'll need to adapt the existing table to support that. I also wasn't sure if the current columns still make sense given that the scraped data does so I just print the raw response roughly inspect the search results.
  • This lacks a functional test of the search flow, similar to the behaviors test in register.test.tsx. We can add that when we start adding the actual UI components

@github-actions
Copy link

github-actions bot commented Oct 19, 2021

Visit the preview URL for this PR (updated for commit alexjball/police-data-trust@20008f4):

https://police-data-trust-dev--pr195-basic-search-0q9d6qjk.web.app

(expires Wed, 27 Oct 2021 00:29:47 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 89ee28768ddf114979e2cf8eddd3746214cf93af


bp = Blueprint("incident_routes", __name__, url_prefix="/api/v1/incidents")


@bp.route("/get/<int:incident_id>", methods=["GET"])
@jwt_required()
@role_required(UserRole.PUBLIC)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm, the way this annotation is implemented right now means that only users with the role public can make this request. Since our roles have a hierarchy, should we change this to mean public or higher?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that change makes sense! Created #196 to track

Comment on lines +48 to +54
class SearchIncidentsSchema(BaseModel, extra="forbid"):
location: Optional[str] = None
startTime: Optional[datetime] = None
endTime: Optional[datetime] = None
description: Optional[str] = None
page: Optional[int] = 1
perPage: Optional[int] = 20
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 our schema definitions are getting a little disorganized, right now we have backend/schemas.py, a single file with a few different unrelated schemas in it, and the files within backend/dto as well. I don't know flask/python well enough to suggest a better system, but it seems like we might want one soon

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah these can definitely be cleaned up. Most of the models in this file are unused. These schemas and the routes make up the public-facing API that will be used by partners and the web app, so we'll also want to be able to version and publish the api spec implied by these schemas. #111 sort of tracks that.

<section style={{ maxWidth: "500px", margin: "1em auto" }}>
<h1>Search Incidents</h1>
<FormProvider {...form}>
<form className={sharedStyles.centerContent} onSubmit={form.handleSubmit(onSubmit)}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is temp UI? we should not be using forms onSubmit method, only the

tag itself but if temp ui then can ignor

Copy link
Member Author

Choose a reason for hiding this comment

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

@JMStudiosJoe Can you explain why? We use onSubmit in all the other forms (registration, passport, login). We're using react-hook-form for control flow not raw html.

@JMStudiosJoe JMStudiosJoe merged commit d8c2563 into codeforboston:main Oct 23, 2021
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.

Basic Incident Search API [FEATURE] Test state of database for many-to-one relations after CRUD.
3 participants