Remove unnecessary comments from codebase
Clean up obvious and redundant comments that don't add value: - Remove step-by-step comments in command handlers - Remove obvious test setup comments - Keep only meaningful comments that explain why, not what
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -119,7 +119,6 @@ func TestUnmarkHabitHandler_ReturnsErrorWhenEntryNotFound(t *testing.T) {
|
||||
habitToReturn: habit,
|
||||
}
|
||||
|
||||
// No entries
|
||||
entryRepo := &mockEntryRepoForUnmark{
|
||||
entries: []*entities.HabitEntry{},
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user