harvard-lil / h2o

H2O is a web app for creating and reading open educational resources, primarily in the legal field
https://opencasebook.org
GNU Affero General Public License v3.0
36 stars 30 forks source link

Optimize endpoint for legal document addition #1947

Closed lizadaly closed 1 year ago

lizadaly commented 1 year ago

In the add content workflow generally, the underlying process to add a legal doc in the front-end code goes:

  1. User searches for a document
  2. User clicks on the selected document
  3. Frontend makes a JSON POST request to the backend that says, "Go get foreign legal doc id 123 from your upstream source if you don't already have it, and tell me its local id"
  4. Once that round-trip happens, issue a form POST request with the casebook id and an optional section id to create the resource as the last item in the casebook or section
  5. The backend creates the resource, then returns a 302 redirect to the annotation page for the new resource

This could be improved in a few ways:

To improve the apparent and actual speed of the "add legal doc" flow for https://github.com/harvard-lil/h2o/issues/1933:

Create a new endpoint that accepts a JSON POST request containing:

  1. The casebook id
  2. The foreign legal doc identifier
  3. The optional section id

and in one response, have it get-or-create the legal doc and associate the legal doc with the casebook at the proscribed section id, if present. It should return a 201 JSON response with the redirect URL and the internal resource id. The frontend can then choose to redirect the user or not.