Add smart notification reminder system with frequency-aware scheduling

Replaces one-size-fits-all "2 days before" reminders with intelligent
scheduling based on task frequency. Infrequent tasks (annual) get 30-day
advance notice while frequent tasks (weekly) only get day-of reminders.

Key features:
- Frequency-aware pre-reminders: annual (30d, 14d, 7d), quarterly (7d, 3d),
  monthly (3d), bi-weekly (1d), daily/weekly/once (day-of only)
- Overdue tapering: daily for 3 days, then every 3 days, stops after 14 days
- Reminder log table prevents duplicate notifications per due date/stage
- Admin endpoint displays notification schedules for all frequencies
- Comprehensive test suite (100 random tasks, 61 days each, 10 test functions)

New files:
- internal/notifications/reminder_config.go - Editable schedule configuration
- internal/notifications/reminder_schedule.go - Schedule lookup logic
- internal/notifications/reminder_schedule_test.go - Dynamic test suite
- internal/models/reminder_log.go - TaskReminderLog model
- internal/repositories/reminder_repo.go - Reminder log repository
- migrations/010_add_task_reminder_log.{up,down}.sql

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-12-19 23:03:28 -06:00
parent 7a57a902bb
commit 69206c6930
13 changed files with 1733 additions and 28 deletions

View File

@@ -50,6 +50,7 @@ type TaskFilterOptions struct {
PreloadAssignedTo bool
PreloadResidence bool
PreloadCompletions bool // Minimal: just id, task_id, completed_at
PreloadFrequency bool // For smart notifications
}
// applyFilterOptions applies the filter options to a query.
@@ -88,6 +89,9 @@ func (r *TaskRepository) applyFilterOptions(query *gorm.DB, opts TaskFilterOptio
return db.Select("id", "task_id", "completed_at")
})
}
if opts.PreloadFrequency {
query = query.Preload("Frequency")
}
return query
}
@@ -209,6 +213,32 @@ func (r *TaskRepository) GetCancelledTasks(opts TaskFilterOptions) ([]models.Tas
return tasks, err
}
// GetActiveTasksForUsers returns all active, non-completed tasks for the specified users.
// This is used by the smart notification system to evaluate all tasks for potential reminders.
// It includes tasks that are overdue, due soon, or upcoming - the caller determines
// which reminders to send based on the task's frequency and due date.
func (r *TaskRepository) GetActiveTasksForUsers(now time.Time, opts TaskFilterOptions) ([]models.Task, error) {
var tasks []models.Task
// Get all active, non-completed tasks
query := r.db.Model(&models.Task{}).
Scopes(task.ScopeActive, task.ScopeNotCompleted)
// Include in-progress tasks if specified
if !opts.IncludeInProgress {
query = query.Scopes(task.ScopeNotInProgress)
}
// Apply filters and preloads
query = r.applyFilterOptions(query, opts)
// Order by due date for consistent processing
query = query.Order("COALESCE(next_due_date, due_date) ASC NULLS LAST")
err := query.Find(&tasks).Error
return tasks, err
}
// === Task CRUD ===
// FindByID finds a task by ID with preloaded relations