-
Notifications
You must be signed in to change notification settings - Fork 11
Refactor taxa list endpoints to follow the project-user membership API #1104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/taxa-lists
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for antenna-preview canceled.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
… model)
Refactors taxa list endpoints to use nested routes and proper HTTP methods
while keeping the simple ManyToManyField (no through model).
**Backend changes:**
- Created TaxaListTaxonViewSet with nested routes under /taxa/lists/{id}/taxa/
- Simple serializers for input validation and output
- Removed deprecated add_taxon/remove_taxon actions from TaxaListViewSet
- Uses Django M2M .add() and .remove() methods directly
**Frontend changes:**
- Updated useAddTaxaListTaxon to POST to /taxa/ endpoint
- Updated useRemoveTaxaListTaxon to use DELETE method
**API changes:**
- POST /taxa/lists/{id}/taxa/ - Add taxon (returns 201, 400 for duplicates)
- DELETE /taxa/lists/{id}/taxa/by-taxon/{taxon_id}/ - Remove taxon (returns 204, 404 for non-existent)
- GET /taxa/lists/{id}/taxa/ - List taxa in list
- Removed POST /taxa/lists/{id}/add_taxon/ (deprecated)
- Removed POST /taxa/lists/{id}/remove_taxon/ (deprecated)
**Benefits:**
- Same API as project membership (consistency)
- No migration needed (keeps existing simple M2M)
- Proper HTTP semantics (POST=201, DELETE=204)
- RESTful nested resource design
**Tests:**
- Added comprehensive test suite (13 tests, all passing)
- Tests for CRUD operations, validation, and error cases
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
3ab6b2f to
1f5e5d4
Compare
| taxon_id: taxonId, | ||
| }, | ||
| axios.delete( | ||
| `${API_URL}/${API_ROUTES.TAXA_LISTS}/${taxaListId}/taxa/by-taxon/${taxonId}/?project_id=${projectId}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is by-taxon in URL intentional or Claude being a bit creative? I think we can skip!

Summary
Refactors taxa list endpoints to use a through model (
TaxaListTaxon) instead of custom POST actions, following the same pattern as the project membership API for consistency and better RESTful design.Changes
Backend
Created TaxaListTaxon through model (
ami/main/models.py:3606)TaxaListandTaxon(taxa_list, taxon)Database migration (
ami/main/migrations/0081_add_taxalist_taxon_through_model.py)TaxaList.taxato use through parameterCreated serializers (
ami/main/api/serializers.py:672)TaxaListTaxonSerializer- Create/update with validationTaxaListTaxonListSerializer- Simplified for list viewsCreated TaxaListTaxonViewSet (
ami/main/api/views.py:1633)delete_by_taxonaction for convenienceUpdated router (
config/api_router.py:40)/taxa/lists/{taxalist_id}/taxa/Removed deprecated actions
add_taxon()action from TaxaListViewSetremove_taxon()action from TaxaListViewSetFrontend
Updated useAddTaxaListTaxon hook
POST /taxa/lists/{id}/add_taxon/toPOST /taxa/lists/{id}/taxa/Updated useRemoveTaxaListTaxon hook
POST /taxa/lists/{id}/remove_taxon/toDELETE /taxa/lists/{id}/taxa/by-taxon/{taxon_id}/Tests
ami/main/tests/test_taxa_list_taxa_api.py)API Changes
New Endpoints
GET /taxa/lists/{id}/taxa/- List taxa in a taxa listPOST /taxa/lists/{id}/taxa/- Add taxon (201 Created, 400 if duplicate)GET /taxa/lists/{id}/taxa/{membership_id}/- Retrieve membership detailsDELETE /taxa/lists/{id}/taxa/{membership_id}/- Remove by membership ID (204 No Content)DELETE /taxa/lists/{id}/taxa/by-taxon/{taxon_id}/- Remove by taxon ID (204 No Content, 404 if not found)Removed Endpoints
(deprecated)POST /taxa/lists/{id}/add_taxon/(deprecated)POST /taxa/lists/{id}/remove_taxon/Benefits
Testing
Checklist
🤖 Generated with Claude Code