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)
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package queries
|
|
|
|
import (
|
|
"context"
|
|
|
|
"apocapoc-api/internal/domain/repositories"
|
|
"apocapoc-api/internal/domain/value_objects"
|
|
)
|
|
|
|
type HabitDTO struct {
|
|
ID string
|
|
Name string
|
|
Type value_objects.HabitType
|
|
Frequency value_objects.Frequency
|
|
TargetValue *float64
|
|
CarryOver bool
|
|
IsNegative bool
|
|
SpecificDays []int
|
|
}
|
|
|
|
type GetUserHabitsQuery struct {
|
|
UserID string
|
|
}
|
|
|
|
type GetUserHabitsHandler struct {
|
|
habitRepo repositories.HabitRepository
|
|
}
|
|
|
|
func NewGetUserHabitsHandler(habitRepo repositories.HabitRepository) *GetUserHabitsHandler {
|
|
return &GetUserHabitsHandler{
|
|
habitRepo: habitRepo,
|
|
}
|
|
}
|
|
|
|
func (h *GetUserHabitsHandler) Handle(ctx context.Context, query GetUserHabitsQuery) ([]HabitDTO, error) {
|
|
habits, err := h.habitRepo.FindActiveByUserID(ctx, query.UserID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var result []HabitDTO
|
|
for _, habit := range habits {
|
|
result = append(result, HabitDTO{
|
|
ID: habit.ID,
|
|
Name: habit.Name,
|
|
Type: habit.Type,
|
|
Frequency: habit.Frequency,
|
|
TargetValue: habit.TargetValue,
|
|
CarryOver: habit.CarryOver,
|
|
IsNegative: habit.IsNegative,
|
|
SpecificDays: habit.SpecificDays,
|
|
})
|
|
}
|
|
|
|
return result, nil
|
|
}
|