Add COUNTER type with auto-increment and IsNegative field
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)
This commit is contained in:
@@ -25,7 +25,7 @@ func (m *mockEntryRepoWithFindByHabitID) FindByHabitIDAndDateRange(ctx context.C
|
||||
}
|
||||
|
||||
func TestGetHabitEntriesHandler_ReturnsEntriesSuccessfully(t *testing.T) {
|
||||
habit := entities.NewHabit("user-123", "Exercise", value_objects.HabitTypeBoolean, value_objects.FrequencyDaily, false)
|
||||
habit := entities.NewHabit("user-123", "Exercise", value_objects.HabitTypeBoolean, value_objects.FrequencyDaily, false, false)
|
||||
habit.ID = "habit-1"
|
||||
|
||||
date1 := time.Date(2025, 1, 15, 0, 0, 0, 0, time.UTC)
|
||||
@@ -101,7 +101,7 @@ func TestGetHabitEntriesHandler_ReturnsErrorWhenHabitNotFound(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetHabitEntriesHandler_ReturnsErrorWhenUserDoesNotOwnHabit(t *testing.T) {
|
||||
habit := entities.NewHabit("user-123", "Exercise", value_objects.HabitTypeBoolean, value_objects.FrequencyDaily, false)
|
||||
habit := entities.NewHabit("user-123", "Exercise", value_objects.HabitTypeBoolean, value_objects.FrequencyDaily, false, false)
|
||||
habit.ID = "habit-1"
|
||||
|
||||
habitRepo := &mockHabitRepoWithFindByID{
|
||||
@@ -127,7 +127,7 @@ func TestGetHabitEntriesHandler_ReturnsErrorWhenUserDoesNotOwnHabit(t *testing.T
|
||||
}
|
||||
|
||||
func TestGetHabitEntriesHandler_WithPagination(t *testing.T) {
|
||||
habit := entities.NewHabit("user-123", "Exercise", value_objects.HabitTypeBoolean, value_objects.FrequencyDaily, false)
|
||||
habit := entities.NewHabit("user-123", "Exercise", value_objects.HabitTypeBoolean, value_objects.FrequencyDaily, false, false)
|
||||
habit.ID = "habit-1"
|
||||
|
||||
entries := make([]*entities.HabitEntry, 10)
|
||||
@@ -179,7 +179,7 @@ func TestGetHabitEntriesHandler_WithPagination(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetHabitEntriesHandler_RequiresPaginationWithoutDateRange(t *testing.T) {
|
||||
habit := entities.NewHabit("user-123", "Exercise", value_objects.HabitTypeBoolean, value_objects.FrequencyDaily, false)
|
||||
habit := entities.NewHabit("user-123", "Exercise", value_objects.HabitTypeBoolean, value_objects.FrequencyDaily, false, false)
|
||||
habit.ID = "habit-1"
|
||||
|
||||
habitRepo := &mockHabitRepoWithFindByID{
|
||||
@@ -207,7 +207,7 @@ func TestGetHabitEntriesHandler_RequiresPaginationWithoutDateRange(t *testing.T)
|
||||
}
|
||||
|
||||
func TestGetHabitEntriesHandler_AllowsNoPaginationWithShortDateRange(t *testing.T) {
|
||||
habit := entities.NewHabit("user-123", "Exercise", value_objects.HabitTypeBoolean, value_objects.FrequencyDaily, false)
|
||||
habit := entities.NewHabit("user-123", "Exercise", value_objects.HabitTypeBoolean, value_objects.FrequencyDaily, false, false)
|
||||
habit.ID = "habit-1"
|
||||
|
||||
from := time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
@@ -247,7 +247,7 @@ func TestGetHabitEntriesHandler_AllowsNoPaginationWithShortDateRange(t *testing.
|
||||
}
|
||||
|
||||
func TestGetHabitEntriesHandler_RequiresPaginationWithLongDateRange(t *testing.T) {
|
||||
habit := entities.NewHabit("user-123", "Exercise", value_objects.HabitTypeBoolean, value_objects.FrequencyDaily, false)
|
||||
habit := entities.NewHabit("user-123", "Exercise", value_objects.HabitTypeBoolean, value_objects.FrequencyDaily, false, false)
|
||||
habit.ID = "habit-1"
|
||||
|
||||
from := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
Reference in New Issue
Block a user