Skip to content

resources filter by category #488

Description

@jacobvenable

Problem

We currently use the category endpoint to serve resources by category (example category page). The issue with this endpoint is that it returns resources as groups of sub-categories, e.g.:

{
  "subcategories": [
      {
         "name": "Meals",
         "resources": [
             {
                "name": "Resource A",
             },
             {
                "name": "Resource B",
             }
         ],
      },
      {
         "name": "Food Pantries",
         "resources": [
             {
                "name": "Resource A",
             },
             {
                "name": "Resource C",
             }
         ],
      }
   ]
}

It's possible to have a resource listed under multiple sub-categories, as shown in the example above where "Resource A" provides both a meal and a food pantry.

This requires the client to filter out repeats of resources.

Solution

Ideally we'd like to have our current resources endpoint support filtering by category. That way, we can use one endpoint for fetching resources.

API Updates

  • add an optional categories query param to the resources endpoint that accepts a string equaling a comma-separated list of categories we wish to filter resources by, e.g. /resources?categories=food,shelter
  • update the useResourcesByCategory hook to consume resources using that updated endpoint

Tech Notes

  • The current /resources endpoint currently supports filtering resources by a list of comma-separated IDs. We'll need to make sure we also honor the current filtering by id that exists on this endpoint. This means that if we provide both ids and categories as filters, we only return resources that match the passed ids AND belong to one or more of the passed categories.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions