Police-Data-Accessibility-Project / data-sources-app

An API and UI for using and maintaining the Data Sources database
MIT License
4 stars 5 forks source link

database: agencies with multiple locations #454

Open josh-chamberlain opened 1 month ago

josh-chamberlain commented 1 month ago

Context

There are cases where multiple localities will share a police department. Thus, we may have localities which aren't represented in our data. Thus, if someone searches for one of those small localities which has no PD, they will not find it in the typeahead.

Let's assume that mapping the jurisdiction of police departments is our job, and allow for the complex nature of jurisdiction.

Requirements

maxachis commented 1 month ago

I could envisioning us updating the POST and PUT requests to a similar structure that we have with /data-requests/{resource_id}/related-sources, but with one caveat:

@joshuagraber , what do you think?

joshuagraber commented 1 month ago

@maxachis That generally sounds good to me. One point of clarification, though:

We would then modify the PUT request so that location_info can't be updated through this fashion

Do you mean a PUT request to /agencies/{resource_id}? If so, can you explain why we wouldn't be able to update location info there and would require a separate endpoint? Are there performance or architectural considerations that make that difficult?

maxachis commented 1 month ago

@joshuagraber The main challenge is that location information is now normalized and centralized in the database. I describe the full process and logic here, but here's the brief for the part relevant to us:

The issues that arise from this are:

  1. It would be difficult to update an agency's locational information only partially -- if in the PUT request you include the state_iso but not county_fips or municipality, do we interpret that as meaning the latter fields are unchanged or that they should be set to NULL? What if you remove the municipality information and say its location is a county? What if the jurisdiction_type changes from State to Federal, which would imply it's not associated with any specific state-level location? I have means of addressing this in my current endpoint design, but it's imperfect and convoluted and I don't like it.
  2. If we have multiple locations, these problems remain and compound, because how do we update one of multiple locations, or potentially several at once, within the PUT request?

It strikes me as easier, for both the user and the backend, to simply have it that you can add and remove locations via a separate endpoint, and leave the PUT request solely for non-locational information about the agency.

I do think it makes sense to enable the inclusion of location information in the original POST request, since most agencies will have locational information attached to them. It just becomes quite hinky if we then enable editing through a PUT request.