diff --git a/internal/application/commands/archive_habit.go b/internal/application/commands/archive_habit.go index 1a3354e..fad93a0 100644 --- a/internal/application/commands/archive_habit.go +++ b/internal/application/commands/archive_habit.go @@ -23,20 +23,16 @@ func NewArchiveHabitHandler(habitRepo repositories.HabitRepository) *ArchiveHabi } func (h *ArchiveHabitHandler) Handle(ctx context.Context, cmd ArchiveHabitCommand) error { - // Find existing habit habit, err := h.habitRepo.FindByID(ctx, cmd.HabitID) if err != nil { return err } - // Check ownership if habit.UserID != cmd.UserID { return errors.ErrUnauthorized } - // Archive the habit (idempotent operation) habit.Archive() - // Save changes return h.habitRepo.Update(ctx, habit) } diff --git a/internal/application/commands/archive_habit_test.go b/internal/application/commands/archive_habit_test.go index 6bbf41a..89af63b 100644 --- a/internal/application/commands/archive_habit_test.go +++ b/internal/application/commands/archive_habit_test.go @@ -98,7 +98,6 @@ func TestArchiveHabitHandler_CanArchiveAlreadyArchivedHabit(t *testing.T) { err := handler.Handle(context.Background(), cmd) - // Should be idempotent - no error if err != nil { t.Fatalf("Expected no error for already archived habit, got %v", err) } diff --git a/internal/application/commands/unmark_habit.go b/internal/application/commands/unmark_habit.go index eb70924..2b24415 100644 --- a/internal/application/commands/unmark_habit.go +++ b/internal/application/commands/unmark_habit.go @@ -30,7 +30,6 @@ func NewUnmarkHabitHandler( } func (h *UnmarkHabitHandler) Handle(ctx context.Context, cmd UnmarkHabitCommand) error { - // Verify habit exists and user owns it habit, err := h.habitRepo.FindByID(ctx, cmd.HabitID) if err != nil { return err @@ -40,8 +39,6 @@ func (h *UnmarkHabitHandler) Handle(ctx context.Context, cmd UnmarkHabitCommand) return errors.ErrUnauthorized } - // Find the entry for the scheduled date - // We search within the same day startOfDay := time.Date( cmd.ScheduledDate.Year(), cmd.ScheduledDate.Month(), @@ -56,7 +53,6 @@ func (h *UnmarkHabitHandler) Handle(ctx context.Context, cmd UnmarkHabitCommand) return err } - // Find the entry for this date var targetEntryID string for _, entry := range entries { if entry.ScheduledDate.Equal(cmd.ScheduledDate) { @@ -69,6 +65,5 @@ func (h *UnmarkHabitHandler) Handle(ctx context.Context, cmd UnmarkHabitCommand) return errors.ErrNotFound } - // Hard delete the entry return h.entryRepo.Delete(ctx, targetEntryID) } diff --git a/internal/application/commands/unmark_habit_test.go b/internal/application/commands/unmark_habit_test.go index 36e23da..9e04506 100644 --- a/internal/application/commands/unmark_habit_test.go +++ b/internal/application/commands/unmark_habit_test.go @@ -119,7 +119,6 @@ func TestUnmarkHabitHandler_ReturnsErrorWhenEntryNotFound(t *testing.T) { habitToReturn: habit, } - // No entries entryRepo := &mockEntryRepoForUnmark{ entries: []*entities.HabitEntry{}, } diff --git a/internal/application/commands/update_habit.go b/internal/application/commands/update_habit.go index 0888a33..4a11d4c 100644 --- a/internal/application/commands/update_habit.go +++ b/internal/application/commands/update_habit.go @@ -30,28 +30,23 @@ func NewUpdateHabitHandler(habitRepo repositories.HabitRepository) *UpdateHabitH } func (h *UpdateHabitHandler) Handle(ctx context.Context, cmd UpdateHabitCommand) error { - // Validate input if strings.TrimSpace(cmd.Name) == "" { return errors.ErrInvalidInput } - // Find existing habit habit, err := h.habitRepo.FindByID(ctx, cmd.HabitID) if err != nil { return err } - // Check ownership if habit.UserID != cmd.UserID { return errors.ErrUnauthorized } - // Cannot update archived habits if !habit.IsActive() { return errors.ErrInvalidInput } - // Update fields habit.Name = cmd.Name habit.Description = cmd.Description habit.CarryOver = cmd.CarryOver @@ -59,6 +54,5 @@ func (h *UpdateHabitHandler) Handle(ctx context.Context, cmd UpdateHabitCommand) habit.SpecificDays = cmd.SpecificDays habit.SpecificDates = cmd.SpecificDates - // Save changes return h.habitRepo.Update(ctx, habit) } diff --git a/internal/domain/entities/user_test.go b/internal/domain/entities/user_test.go index 1b479b5..e2e0b65 100644 --- a/internal/domain/entities/user_test.go +++ b/internal/domain/entities/user_test.go @@ -32,7 +32,6 @@ func TestNewUser(t *testing.T) { t.Error("UpdatedAt should not be zero") } - // CreatedAt and UpdatedAt should be very close in time diff := user.UpdatedAt.Sub(user.CreatedAt) if diff < 0 || diff > time.Second { t.Errorf("CreatedAt and UpdatedAt should be nearly identical, diff: %v", diff) diff --git a/internal/shared/utils/date_utils_test.go b/internal/shared/utils/date_utils_test.go index b07d5d6..dad30d2 100644 --- a/internal/shared/utils/date_utils_test.go +++ b/internal/shared/utils/date_utils_test.go @@ -6,7 +6,6 @@ import ( ) func TestShouldAppearToday_Daily(t *testing.T) { - // Daily habits should always appear result := ShouldAppearToday("DAILY", nil, nil, time.Now()) if !result { t.Error("Daily habit should appear every day")