10d45fc34e
COUNTER type: - Only accepts integer values (rejects decimals) - Auto-increment behavior: each mark adds to existing value - Supports decrement via negative values (e.g., -2) - Enforces minimum value of 0 (never negative) - Default increment is 1 if no value provided VALUE type: - Accepts decimal values - Replaces value (no auto-increment) IsNegative field: - New boolean field on Habit entity - Persisted in database (is_negative column) - Available in all DTOs and HTTP responses - Marks habits as "negative" (e.g., candy consumption) Examples: - COUNTER: 5 + (-2) = 3, 2 + (-3) = 0, 0 + (-1) = 0 - VALUE: 5000 → 12000 = 12000 (replacement)
52 lines
920 B
Go
52 lines
920 B
Go
package entities
|
|
|
|
import (
|
|
"time"
|
|
|
|
"apocapoc-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
|
|
IsNegative 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,
|
|
isNegative bool,
|
|
) *Habit {
|
|
return &Habit{
|
|
UserID: userID,
|
|
Name: name,
|
|
Type: habitType,
|
|
Frequency: frequency,
|
|
CarryOver: carryOver,
|
|
IsNegative: isNegative,
|
|
CreatedAt: time.Now(),
|
|
}
|
|
}
|
|
|
|
func (h *Habit) Archive() {
|
|
now := time.Now()
|
|
h.ArchivedAt = &now
|
|
}
|
|
|
|
func (h *Habit) IsActive() bool {
|
|
return h.ArchivedAt == nil
|
|
}
|