- Created app/routers/api_crud_v3_nested.py to handle all parent-child relational routes. - Updated app/routers/api_crud_v3.py to include the nested router, significantly reducing file size. - Documented Phase 2 completion in documentation/REFACTOR_API_CRUD_V3.md.
1.3 KiB
1.3 KiB
Refactoring Plan: API CRUD V3
Goal: Modularize app/routers/api_crud_v3.py to improve maintainability, readability, and reusability. The file currently mixes route definitions, security enforcement, data sanitization, and helper utilities.
Phase 1: Extract Helpers & Core Logic (Safest) - COMPLETED
Objective: Move pure functions and business logic out of the router file.
- Create
app/lib_api_crud_v3.py: DONE - Update
app/routers/api_crud_v3.py: DONE (All endpoints now usesanitize_payload).
Phase 2: Separate Child/Nested Routes - COMPLETED
Objective: Reduce file size by splitting standard CRUD from relational CRUD.
- Create
app/routers/api_crud_v3_nested.py: DONE - Update
app/routers/api_crud_v3.py: DONE (Included viarouter.include_router)
Phase 3: Schema Introspection - PLANNED
- Create
app/lib_schema_v3.py(or similar):- Move the logic inside
get_obj_schema(SQLDESCRIBEparsing, Pydantic introspection) to a helper function.
- Move the logic inside
Execution Strategy
We will execute Phase 1 first as it provides immediate value (removing code duplication for sanitization) with minimal risk to routing logic.
Testing
After each move:
- Run
tests/test_v3_router_filtering.py(requires update to import from new location if we test the lib directly). - Verify application startup.