upswyng
upswyng copied to clipboard
resources filter by category
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 byid
that exists on this endpoint. This means that if we provide bothids
andcategories
as filters, we only return resources that match the passed ids AND belong to one or more of the passed categories.
Being taken on @Sunset05