Improve type safety with proper value objects for HabitType and Frequency
Replace generic string types with strongly-typed value objects throughout the application layer. This change ensures compile-time type checking and automatic validation during JSON deserialization. Changes: - Add JSON marshaling/unmarshaling to HabitType and Frequency value objects - Update all DTOs to use typed fields instead of strings - Update commands and queries to use proper types - Remove unnecessary string conversions - Add comprehensive JSON serialization tests - Fix existing tests to work with typed fields Benefits: - Type safety: compiler catches invalid usage - Automatic validation: invalid values rejected during JSON parsing - Better code documentation and self-explanatory APIs - Reduced runtime errors
This commit is contained in:
@@ -35,8 +35,8 @@ func (h *GetHabitByIDHandler) Handle(ctx context.Context, query GetHabitByIDQuer
|
||||
return &HabitDTO{
|
||||
ID: habit.ID,
|
||||
Name: habit.Name,
|
||||
Type: string(habit.Type),
|
||||
Frequency: string(habit.Frequency),
|
||||
Type: habit.Type,
|
||||
Frequency: habit.Frequency,
|
||||
TargetValue: habit.TargetValue,
|
||||
CarryOver: habit.CarryOver,
|
||||
SpecificDays: habit.SpecificDays,
|
||||
|
||||
Reference in New Issue
Block a user