feat(domain): add core entities — Club, Member, WorkItem, Shift with state machine
- Create domain entities in WorkClub.Domain/Entities: Club, Member, WorkItem, Shift, ShiftSignup - Implement enums: SportType, ClubRole, WorkItemStatus - Add ITenantEntity interface for multi-tenancy support - Implement state machine validation on WorkItem with C# 14 switch expressions - Valid transitions: Open→Assigned→InProgress→Review→Done, Review→InProgress (rework) - All invalid transitions throw InvalidOperationException - TDD approach: Write tests first, 12/12 passing - Use required properties with explicit Guid/Guid? for foreign keys - DateTimeOffset for timestamps (timezone-aware, multi-tenant friendly) - RowVersion byte[] for optimistic concurrency control - No navigation properties yet (deferred to EF Core task) - No domain events or validation attributes (YAGNI for MVP)
This commit is contained in:
29
.sisyphus/evidence/task-4-state-machine-invalid.txt
Normal file
29
.sisyphus/evidence/task-4-state-machine-invalid.txt
Normal file
@@ -0,0 +1,29 @@
|
||||
# Evidence: WorkItem State Machine Invalid Transitions Validation
|
||||
|
||||
All invalid transition tests verified to throw InvalidOperationException:
|
||||
|
||||
✓ Open_ToDone_Throws - Cannot skip states
|
||||
✓ Open_ToInProgress_Throws - Must assign first
|
||||
✓ Assigned_ToDone_Throws - Must go through review
|
||||
✓ InProgress_ToOpen_Throws - No backwards transition
|
||||
✓ Done_ToAnyStatus_Throws - Terminal state enforcement
|
||||
|
||||
State machine implementation correctly enforces:
|
||||
- Valid transitions: Open → Assigned → InProgress → Review → Done
|
||||
- Rework allowed: Review → InProgress
|
||||
- All invalid transitions throw InvalidOperationException
|
||||
|
||||
Implementation in WorkClub.Domain/Entities/WorkItem.cs using C# 14 switch expression:
|
||||
```csharp
|
||||
public bool CanTransitionTo(WorkItemStatus newStatus) => (Status, newStatus) switch
|
||||
{
|
||||
(WorkItemStatus.Open, WorkItemStatus.Assigned) => true,
|
||||
(WorkItemStatus.Assigned, WorkItemStatus.InProgress) => true,
|
||||
(WorkItemStatus.InProgress, WorkItemStatus.Review) => true,
|
||||
(WorkItemStatus.Review, WorkItemStatus.Done) => true,
|
||||
(WorkItemStatus.Review, WorkItemStatus.InProgress) => true,
|
||||
_ => false
|
||||
};
|
||||
```
|
||||
|
||||
All 12 test cases passed successfully.
|
||||
Reference in New Issue
Block a user