Feature Implementation Plan: Standardize API Filtering Parameters (Backend)¶
📋 Todo Checklist¶
- [ ] Update the
/api/coffee-beansendpoint to changeroasterIdtoroasterIds[]. - [ ] Update the
/api/coffee-beansendpoint to changecountryIdtocountryIds[]. - [ ] Update the
api_filters.yamlconfiguration to reflect these changes. - [ ] Update the OpenAPI documentation (annotations) for the endpoint.
- [ ] Update integration tests to use the new parameters.
- [ ] Final Review and Testing
🔍 Analysis & Investigation¶
Codebase Structure¶
- Metadata Source: The OpenAPI annotations in
src/Controller/Api/CoffeeBeanController.phpforroasterIdandcountryIdwill be modified. - Filtering Logic: The configuration keys in
config/packages/api_filters.yamlwill be updated to match the new parameter names and types.
Current Architecture & Problem¶
- Problem: The API is inconsistent. Most ID-based filters accept arrays (e.g.,
speciesIds[]), butroasterIdandcountryIdonly accept a single value. This makes the API less predictable. - Solution: This plan standardizes all ID-based filters to be plural and accept arrays. This is a breaking change that will significantly improve API consistency. There is no requirement for backward compatibility.
Dependencies & Integration Points¶
- FilterService: The
FilterServiceis already capable of handlinguuid_arraytypes, so no changes are needed in the service itself, only in its configuration. - NelmioApiDocBundle: Correcting the annotations in the controller is crucial for ensuring the
/api/filters/metadataendpoint and the OpenAPI documentation accurately reflect the API's behavior.
📝 Implementation Plan¶
Prerequisites¶
- No new external dependencies are required.
Step-by-Step Implementation¶
-
Update
CoffeeBeanControllerAnnotations- Files to modify:
src/Controller/Api/CoffeeBeanController.php - Changes needed:
- Locate the
#[OA\Parameter]forroasterId.- Change the
namefrom'roasterId'to'roasterIds[]'. - Update the
schemato benew OA\Schema(type: 'array', items: new OA\Items(type: 'string', format: 'uuid')). - Add
style: 'form', explode: true.
- Change the
- Locate the
#[OA\Parameter]forcountryId.- Change the
namefrom'countryId'to'countryIds[]'. - Update the
schemato benew OA\Schema(type: 'array', items: new OA\Items(type: 'string', format: 'uuid')). - Add
style: 'form', explode: true.
- Change the
- Locate the
- Files to modify:
-
Update Filter Configuration
- Files to modify:
config/packages/api_filters.yaml - Changes needed:
- In the
api_filterssection forApp\Entity\CoffeeBean: - Rename the
roasterIdkey toroasterIds. - Change its
typefrom'uuid'to'uuid_array'. - Update the
fieldto point to the'roaster'relationship. - Rename the
countryIdkey tocountryIds. - Change its
typefrom'uuid'to'uuid_array'. - Update the
fieldto point to the'country'relationship.
- In the
- Files to modify:
Testing Strategy¶
- Integration Tests:
- Find and update any existing integration tests for
/api/coffee-beansthat useroasterIdorcountryIdand change them to use the newroasterIds[]andcountryIds[]parameters. - Add a new test case that passes multiple
roasterIds[]to ensure the array filtering works correctly. - Add a new test case that passes multiple
countryIds[]to ensure the array filtering works correctly. - Update the test for
/api/filters/metadatato assert that the keys are nowroasterIdsandcountryIdsand theirtypeisarray.
- Find and update any existing integration tests for
🎯 Success Criteria¶
- The
roasterIdandcountryIdparameters are successfully replaced byroasterIds[]andcountryIds[]on the/api/coffee-beansendpoint. - The API correctly filters by an array of roaster and country IDs.
- The
/api/filters/metadataendpoint and the OpenAPI documentation accurately reflect these changes. - All ID-based filters on the
/api/coffee-beansendpoint are now consistently array-based.