358f844073
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
39 lines
730 B
Go
39 lines
730 B
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
|
|
"apocapoc-api/internal/domain/repositories"
|
|
"apocapoc-api/internal/shared/errors"
|
|
)
|
|
|
|
type ArchiveHabitCommand struct {
|
|
HabitID string
|
|
UserID string
|
|
}
|
|
|
|
type ArchiveHabitHandler struct {
|
|
habitRepo repositories.HabitRepository
|
|
}
|
|
|
|
func NewArchiveHabitHandler(habitRepo repositories.HabitRepository) *ArchiveHabitHandler {
|
|
return &ArchiveHabitHandler{
|
|
habitRepo: habitRepo,
|
|
}
|
|
}
|
|
|
|
func (h *ArchiveHabitHandler) Handle(ctx context.Context, cmd ArchiveHabitCommand) error {
|
|
habit, err := h.habitRepo.FindByID(ctx, cmd.HabitID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if habit.UserID != cmd.UserID {
|
|
return errors.ErrUnauthorized
|
|
}
|
|
|
|
habit.Archive()
|
|
|
|
return h.habitRepo.Update(ctx, habit)
|
|
}
|