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 {
|
func (h *ArchiveHabitHandler) Handle(ctx context.Context, cmd ArchiveHabitCommand) error {
|
||||||
// Find existing habit
|
|
||||||
habit, err := h.habitRepo.FindByID(ctx, cmd.HabitID)
|
habit, err := h.habitRepo.FindByID(ctx, cmd.HabitID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check ownership
|
|
||||||
if habit.UserID != cmd.UserID {
|
if habit.UserID != cmd.UserID {
|
||||||
return errors.ErrUnauthorized
|
return errors.ErrUnauthorized
|
||||||
}
|
}
|
||||||
|
|
||||||
// Archive the habit (idempotent operation)
|
|
||||||
habit.Archive()
|
habit.Archive()
|
||||||
|
|
||||||
// Save changes
|
|
||||||
return h.habitRepo.Update(ctx, habit)
|
return h.habitRepo.Update(ctx, habit)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,6 @@ func TestArchiveHabitHandler_CanArchiveAlreadyArchivedHabit(t *testing.T) {
|
|||||||
|
|
||||||
err := handler.Handle(context.Background(), cmd)
|
err := handler.Handle(context.Background(), cmd)
|
||||||
|
|
||||||
// Should be idempotent - no error
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Expected no error for already archived habit, got %v", err)
|
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 {
|
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)
|
habit, err := h.habitRepo.FindByID(ctx, cmd.HabitID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -40,8 +39,6 @@ func (h *UnmarkHabitHandler) Handle(ctx context.Context, cmd UnmarkHabitCommand)
|
|||||||
return errors.ErrUnauthorized
|
return errors.ErrUnauthorized
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the entry for the scheduled date
|
|
||||||
// We search within the same day
|
|
||||||
startOfDay := time.Date(
|
startOfDay := time.Date(
|
||||||
cmd.ScheduledDate.Year(),
|
cmd.ScheduledDate.Year(),
|
||||||
cmd.ScheduledDate.Month(),
|
cmd.ScheduledDate.Month(),
|
||||||
@@ -56,7 +53,6 @@ func (h *UnmarkHabitHandler) Handle(ctx context.Context, cmd UnmarkHabitCommand)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the entry for this date
|
|
||||||
var targetEntryID string
|
var targetEntryID string
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
if entry.ScheduledDate.Equal(cmd.ScheduledDate) {
|
if entry.ScheduledDate.Equal(cmd.ScheduledDate) {
|
||||||
@@ -69,6 +65,5 @@ func (h *UnmarkHabitHandler) Handle(ctx context.Context, cmd UnmarkHabitCommand)
|
|||||||
return errors.ErrNotFound
|
return errors.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hard delete the entry
|
|
||||||
return h.entryRepo.Delete(ctx, targetEntryID)
|
return h.entryRepo.Delete(ctx, targetEntryID)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,6 @@ func TestUnmarkHabitHandler_ReturnsErrorWhenEntryNotFound(t *testing.T) {
|
|||||||
habitToReturn: habit,
|
habitToReturn: habit,
|
||||||
}
|
}
|
||||||
|
|
||||||
// No entries
|
|
||||||
entryRepo := &mockEntryRepoForUnmark{
|
entryRepo := &mockEntryRepoForUnmark{
|
||||||
entries: []*entities.HabitEntry{},
|
entries: []*entities.HabitEntry{},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,28 +30,23 @@ func NewUpdateHabitHandler(habitRepo repositories.HabitRepository) *UpdateHabitH
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *UpdateHabitHandler) Handle(ctx context.Context, cmd UpdateHabitCommand) error {
|
func (h *UpdateHabitHandler) Handle(ctx context.Context, cmd UpdateHabitCommand) error {
|
||||||
// Validate input
|
|
||||||
if strings.TrimSpace(cmd.Name) == "" {
|
if strings.TrimSpace(cmd.Name) == "" {
|
||||||
return errors.ErrInvalidInput
|
return errors.ErrInvalidInput
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find existing habit
|
|
||||||
habit, err := h.habitRepo.FindByID(ctx, cmd.HabitID)
|
habit, err := h.habitRepo.FindByID(ctx, cmd.HabitID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check ownership
|
|
||||||
if habit.UserID != cmd.UserID {
|
if habit.UserID != cmd.UserID {
|
||||||
return errors.ErrUnauthorized
|
return errors.ErrUnauthorized
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cannot update archived habits
|
|
||||||
if !habit.IsActive() {
|
if !habit.IsActive() {
|
||||||
return errors.ErrInvalidInput
|
return errors.ErrInvalidInput
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update fields
|
|
||||||
habit.Name = cmd.Name
|
habit.Name = cmd.Name
|
||||||
habit.Description = cmd.Description
|
habit.Description = cmd.Description
|
||||||
habit.CarryOver = cmd.CarryOver
|
habit.CarryOver = cmd.CarryOver
|
||||||
@@ -59,6 +54,5 @@ func (h *UpdateHabitHandler) Handle(ctx context.Context, cmd UpdateHabitCommand)
|
|||||||
habit.SpecificDays = cmd.SpecificDays
|
habit.SpecificDays = cmd.SpecificDays
|
||||||
habit.SpecificDates = cmd.SpecificDates
|
habit.SpecificDates = cmd.SpecificDates
|
||||||
|
|
||||||
// Save changes
|
|
||||||
return h.habitRepo.Update(ctx, habit)
|
return h.habitRepo.Update(ctx, habit)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ func TestNewUser(t *testing.T) {
|
|||||||
t.Error("UpdatedAt should not be zero")
|
t.Error("UpdatedAt should not be zero")
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatedAt and UpdatedAt should be very close in time
|
|
||||||
diff := user.UpdatedAt.Sub(user.CreatedAt)
|
diff := user.UpdatedAt.Sub(user.CreatedAt)
|
||||||
if diff < 0 || diff > time.Second {
|
if diff < 0 || diff > time.Second {
|
||||||
t.Errorf("CreatedAt and UpdatedAt should be nearly identical, diff: %v", diff)
|
t.Errorf("CreatedAt and UpdatedAt should be nearly identical, diff: %v", diff)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestShouldAppearToday_Daily(t *testing.T) {
|
func TestShouldAppearToday_Daily(t *testing.T) {
|
||||||
// Daily habits should always appear
|
|
||||||
result := ShouldAppearToday("DAILY", nil, nil, time.Now())
|
result := ShouldAppearToday("DAILY", nil, nil, time.Now())
|
||||||
if !result {
|
if !result {
|
||||||
t.Error("Daily habit should appear every day")
|
t.Error("Daily habit should appear every day")
|
||||||
|
|||||||
Reference in New Issue
Block a user