feat(application): implement US1 relay control use cases
Add GetAllRelaysUseCase (T043) for retrieving all 8 relay states with labels, coordinating controller reads and repository label lookups with comprehensive error handling and logging. Implement ToggleRelayUseCase (T041) for toggling individual relay states with read-before-write pattern, state validation, and label retrieval. Add use_cases module (T044) with trait-based dependency injection for testability, exposing both use cases for presentation layer integration. Comprehensive test coverage includes 7 toggle tests (state transitions, error handling, double-toggle idempotency) and 9 get-all tests (count, ordering, state correctness, label inclusion, error scenarios). Ref: T041 T042 T043 T044 (specs/001-modbus-relay-control/tasks.org)
This commit is contained in:
@@ -586,31 +586,38 @@ CLOSED: [2026-01-22 jeu. 00:02]
|
||||
|
||||
--------------
|
||||
|
||||
** TODO Phase 4: US1 - Monitor & Toggle Relay States (MVP) (2 days) [0/5]
|
||||
** STARTED Phase 4: US1 - Monitor & Toggle Relay States (MVP) (2 days) [1/5]
|
||||
- State "STARTED" from "TODO" [2026-01-23 ven. 20:20]
|
||||
*Goal*: View current state of all 8 relays + toggle individual relay on/off
|
||||
|
||||
*Independent Test*: =GET /api/relays= returns 8 relays, =POST /api/relays/{id}/toggle= changes state
|
||||
|
||||
*** TODO Application Layer [0/4]
|
||||
- [ ] *T041* [US1] [TDD] Write tests for =ToggleRelayUseCase=
|
||||
*** DONE Application Layer [4/4]
|
||||
CLOSED: [2026-01-23 ven. 20:42]
|
||||
- State "DONE" from "STARTED" [2026-01-23 ven. 20:42]
|
||||
- State "STARTED" from "TODO" [2026-01-23 ven. 20:20]
|
||||
- [X] *T041* [US1] [TDD] Write tests for =ToggleRelayUseCase=
|
||||
- Test: =execute(RelayId(1))= toggles relay state via controller
|
||||
- Test: =execute()= returns error if controller fails
|
||||
- *File*: =src/application/use_cases/toggle_relay.rs=
|
||||
- *Complexity*: Low | *Uncertainty*: Low
|
||||
- [ ] *T042* [US1] [TDD] Implement =ToggleRelayUseCase=
|
||||
- *Tests Written*: 7 tests covering toggle Off→On, On→Off, error handling, state updates, label retrieval, and double-toggle idempotency
|
||||
- [X] *T042* [US1] [TDD] Implement =ToggleRelayUseCase=
|
||||
- Orchestrate: read current state → toggle → write new state
|
||||
- *File*: =src/application/use_cases/toggle_relay.rs=
|
||||
- *Complexity*: Low | *Uncertainty*: Low
|
||||
- [ ] *T043* [P] [US1] [TDD] Write tests for =GetAllRelaysUseCase=
|
||||
- [X] *T043* [P] [US1] [TDD] Write tests for =GetAllRelaysUseCase=
|
||||
- Test: =execute()= returns all 8 relays with states
|
||||
- *File*: =src/application/use_cases/get_all_relays.rs=
|
||||
- *Complexity*: Low | *Uncertainty*: Low
|
||||
- [ ] *T044* [P] [US1] [TDD] Implement =GetAllRelaysUseCase=
|
||||
- *Tests Written*: 9 tests covering relay count, ordering, state correctness, label inclusion, error handling, and property validation
|
||||
- [X] *T044* [P] [US1] [TDD] Implement =GetAllRelaysUseCase=
|
||||
- Call =controller.read_all()=, map to domain =Relay= objects
|
||||
- *File*: =src/application/use_cases/get_all_relays.rs=
|
||||
- *Complexity*: Low | *Uncertainty*: Low
|
||||
|
||||
*** TODO Presentation Layer (Backend API) [0/2]
|
||||
*** STARTED Presentation Layer (Backend API) [0/2]
|
||||
- State "STARTED" from "TODO" [2026-01-23 ven. 20:42]
|
||||
- [ ] *T045* [US1] [TDD] Define =RelayDto= in presentation layer
|
||||
- Fields: =id= (=u8=), =state= ("on"/"off"), =label= (=Option=)
|
||||
- Implement =From= for =RelayDto=
|
||||
|
||||
Reference in New Issue
Block a user