Implement domain layer (TDD - Green phase)
Implementation to make all tests pass: Value Objects: - HabitType: BOOLEAN, COUNTER, VALUE with validation - Frequency: DAILY, WEEKLY, MONTHLY with validation Entities: - User: email, password hash, timezone with defaults - Habit: tracking habits with type, frequency, carry-over - HabitEntry: recording habit completions with soft delete Repositories (interfaces): - UserRepository: CRUD operations for users - HabitRepository: CRUD operations for habits - HabitEntryRepository: CRUD operations for entries Shared: - Common error definitions for domain layer All domain tests now pass.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"habit-tracker-api/internal/domain/value_objects"
|
||||
)
|
||||
|
||||
type Habit struct {
|
||||
ID string
|
||||
UserID string
|
||||
Name string
|
||||
Description string
|
||||
Type value_objects.HabitType
|
||||
Frequency value_objects.Frequency
|
||||
SpecificDays []int
|
||||
SpecificDates []int
|
||||
CarryOver bool
|
||||
TargetValue *float64
|
||||
CreatedAt time.Time
|
||||
ArchivedAt *time.Time
|
||||
}
|
||||
|
||||
func NewHabit(
|
||||
userID string,
|
||||
name string,
|
||||
habitType value_objects.HabitType,
|
||||
frequency value_objects.Frequency,
|
||||
carryOver bool,
|
||||
) *Habit {
|
||||
return &Habit{
|
||||
UserID: userID,
|
||||
Name: name,
|
||||
Type: habitType,
|
||||
Frequency: frequency,
|
||||
CarryOver: carryOver,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Habit) Archive() {
|
||||
now := time.Now()
|
||||
h.ArchivedAt = &now
|
||||
}
|
||||
|
||||
func (h *Habit) IsActive() bool {
|
||||
return h.ArchivedAt == nil
|
||||
}
|
||||
Reference in New Issue
Block a user