Refactor: Migrate LocalNetworkSettings to Service Layer Architecture - #536
Conversation
…models Refactor DHCPReservationsProvider to comply with architecture guidelines by: - Create DHCPReservationUIModel for presentation layer usage - Extract JNAP operations into LocalNetworkSettingsService (shared service) - Create DHCPReservationsService for business logic - Remove JNAP model imports from Provider, State, and View layers - Implement comprehensive test coverage (28 tests): * DHCPReservationUIModel: 11 tests (100% coverage) * LocalNetworkSettingsService: 11 tests (90.9% coverage) * DHCPReservationsService: 6 tests (isConflict logic) This is Phase 1 of the refactoring. LocalNetworkSettingsService is designed to be shared with LocalNetworkSettingsProvider for future Phase 2 refactoring. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…ayer - Changed LocalNetworkStatus.dhcpReservationList from JNAP DHCPReservation to DHCPReservationUIModel - Service layer now handles all JNAP ↔ UI model conversions through private methods - Removed JNAP dependencies from Provider and State layers - Updated DHCPReservationsProvider to work with UI models - Updated device_detail_view to use DHCPReservationUIModel - Fixed use_build_context_synchronously warning in local_network_settings_view - Renamed reservation_item_ui_model.dart to dhcp_reservation_ui_model.dart for clarity - Updated all tests to reflect new model structure - Removed obsolete test mocks (535 lines deleted) This refactoring achieves complete separation of concerns per Constitution Article V Section 5.3: - Provider/State layers: UI models only, no JNAP knowledge - Service layer: Handles JNAP communication and model transformation - View layer: Presentation logic with UI models
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||||||
User description
Summary
This PR completes the architectural refactoring of the LocalNetworkSettings feature to comply with Constitution Article V Section 5.3 (架構層次與職責分離). The refactoring achieves complete separation of concerns across Provider, Service, and View layers.
Key Changes
LocalNetworkStatus.dhcpReservationListfrom JNAPDHCPReservationto UIDHCPReservationUIModelLocalNetworkSettingsServicethrough private conversion methodsDHCPReservationsProviderto work exclusively with UI modelsdevice_detail_viewto useDHCPReservationUIModeluse_build_context_synchronouslywarning inlocal_network_settings_viewreservation_item_ui_model.darttodhcp_reservation_ui_model.dartfor clarityArchitecture Compliance
Constitution Article V Section 5.3 - 架構層次與職責分離
✅ Provider/State Layers
✅ Service Layer
✅ View Layer
Files Changed
Core Implementation (8 files)
lib/page/advanced_settings/local_network_settings/models/dhcp_reservation_ui_model.dart(new)lib/page/advanced_settings/local_network_settings/providers/dhcp_reservations_provider.dartlib/page/advanced_settings/local_network_settings/providers/local_network_settings_provider.dart(-145 lines)lib/page/advanced_settings/local_network_settings/providers/local_network_settings_state.dartlib/page/advanced_settings/local_network_settings/services/dhcp_reservations_service.dart(new)lib/page/advanced_settings/local_network_settings/services/local_network_settings_service.dart(+189 lines)lib/page/advanced_settings/local_network_settings/views/dhcp_reservations_view.dartlib/page/instant_device/views/device_detail_view.dartTest Coverage (8 files)
Test Plan
Breaking Changes
None - This is a pure architectural refactoring with no API changes.
🤖 Generated with Claude Code
PR Type
Enhancement, Tests
Description
Migrate LocalNetworkSettings to service layer with UI models
Implement comprehensive service layer architecture
Add extensive test coverage for new services
Fix use_build_context_synchronously warnings in views
Diagram Walkthrough
File Walkthrough
9 files
Create new UI model for DHCP reservationsExtract JNAP communication and model conversionsCreate service for DHCP reservation business logicRemove JNAP dependencies, delegate to service layerReplace JNAP DHCPReservation with UI modelUpdate to use UI models and service layerReplace JNAP model with DHCPReservationUIModelUpdate to use DHCPReservationUIModel directlyUpdate to use DHCPReservationUIModel1 files
Fix use_build_context_synchronously warnings8 files
Add comprehensive unit tests for UI modelAdd service layer tests for JNAP communicationAdd tests for DHCP reservation business logicCreate test data builder for DHCP reservationsCreate test data builder for LAN settingsUpdate mocks to use DHCPReservationUIModelUpdate mocks to use DHCPReservationUIModelUpdate test to use DHCPReservationUIModel