oaregithub / oare_mono

1 stars 0 forks source link

Backend for Bibliography Page #1205

Closed hbludworth closed 2 years ago

hbludworth commented 2 years ago

As mentioned in the bibliography overview issue, you'll also create a new page called Bibliography. Before you create the page, we'll want to create the backend code we need to get things working. That way the frontend will be easy to implement.

Luckily, this backend code will actually be very similar to the backend you created for individual citations.

For this backend code, you will create a new backend route. It can simply be the /bibliography GET route. It should return an array of bibliography items.

Now for a description of what needs to happen here. This page will basically be a frontend representation of the existing bibliography table in the database. Instead of pulling citation info for a certain text, this is basically just a list of all bibliographic references and they're associated PDF documents. As such, you basically just have to do the second half of the backend code that you wrote previously because you don't have to get the right citations for just one text, but all of them.

Let's walk through this step by step.

  1. Query all rows in bibliography

    For each row in the bibliography table, you'll want to get the zot_item_key. This may seem like likes it's as easy as doing SELECT uuid, zot_item_key from bibliography. However, there is a catch! There are a lot of rows in bibliography and there eventually will be a lot more. We do NOT want to query all of them at once because it would eventually slow down a ton. So, we'll want to "paginate" the response. This simply means that it splits the results into pages and only returns the page you're querying. So, on the frontend, when viewing the first page it would only query the first page. Once you clicked the second page, it would send another request to the server for the second page. You can also select how many items to display per page. Luckily there are probably 25 examples of Pagination on the site already. Look for any of these examples to learn how to implement it here. Let me know if you have questions about it. This will require that you pass in Pagination values in the HTTP route.

  2. Querying Zotero

    Much like the last backend route you wrote, you'll use these Zotero keys to query Zotero's API to get bibliography info. There is one primary difference. Instead of getting the citation info, you'll want to get the bibliography information. So, you'll query something like this: https://api.zotero.org/groups/318265/items/{ZOTERO ITEM KEY}?format=json&include=bib,data&style=chicago-author-date. You may have noticed that the include parameter changed to bib,data to signify that we want the bib info as well as data info (which we'll use later). As far as I can tell looking through the documentation, there isn't a way to query multiple keys at once, so you'll have to make a request for EACH Zotero key you have. Be sure to read through the documentation to make sure that's the case: https://www.zotero.org/support/dev/web_api/v3/basics . For now, the chicago-author-date in the example query above is fine, but we'll deal with that later.

  3. Add support for varying styles

    As you probably noticed above, the Zotero query referenced style=chicago-author-date. This is because it is using that standard to style the bibliography reference. Dr. Stratford wants the user to be able to select different styles on the frontend. So, you'll want to make sure that this can change. Luckily, this is easy! You can just change the route to be something like /bibliography/:style. Then use that request parameter in the Zotero query.

  4. Getting the resource link

    This will be exactly the same as getting the resource link in the previously done backend route. Just make sure you get the resource link for ALL the bibliography uuids you have.

  5. Getting the file URL from AWS S3

    This will also be the same as the last backend route. For each resource link, use the s3.getSignedUrlPromise function to generate a URL It will primarily be the same as last time, so reference that specification if you need assistance.

  6. Returning it all

    Finally, you'll want to return this info. Return an array with all of this. It will be a paginated list of bibliography HTML and PDF URLs.

  7. Connect the permission

    Using the permission you created previously, add a permissionRoute to this new backend route to block out people that don't have bibliography permission.

BONUS POINTS: At some point on the frontend, we'll want to be able to have columns for the work's Title, Author, and Date. This information is all included in the data property returned by the Zotero API. That is why we queried include=bib,data. If you can extract that information for each item and return it inside of each array object, that will be great!

10808249 commented 2 years ago
  1. extractPagination