Migrate from Gin to Echo framework and add comprehensive integration tests

Major changes:
- Migrate all handlers from Gin to Echo framework
- Add new apperrors, echohelpers, and validator packages
- Update middleware for Echo compatibility
- Add ArchivedHandler to task categorization chain (archived tasks go to cancelled_tasks column)
- Add 6 new integration tests:
  - RecurringTaskLifecycle: NextDueDate advancement for weekly/monthly tasks
  - MultiUserSharing: Complex sharing with user removal
  - TaskStateTransitions: All state transitions and kanban column changes
  - DateBoundaryEdgeCases: Threshold boundary testing
  - CascadeOperations: Residence deletion cascade effects
  - MultiUserOperations: Shared residence collaboration
- Add single-purpose repository functions for kanban columns (GetOverdueTasks, GetDueSoonTasks, etc.)
- Fix RemoveUser route param mismatch (userId -> user_id)
- Fix determineExpectedColumn helper to correctly prioritize in_progress over overdue

🤖 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-16 13:52:08 -06:00
parent c51f1ce34a
commit 6dac34e373
98 changed files with 8209 additions and 4425 deletions

View File

@@ -91,16 +91,18 @@ func EffectiveDate(task *models.Task) *time.Time {
return task.DueDate
}
// IsOverdue returns true if the task's effective date is in the past.
// IsOverdue returns true if the task's effective date is before today.
//
// A task is overdue when:
// - It has an effective date (NextDueDate or DueDate)
// - That date is before the given time
// - That date is before the start of the current day
// - The task is not completed, cancelled, or archived
//
// Note: A task due "today" is NOT overdue. It becomes overdue tomorrow.
//
// SQL equivalent (in scopes.go ScopeOverdue):
//
// COALESCE(next_due_date, due_date) < ?
// COALESCE(next_due_date, due_date) < DATE_TRUNC('day', ?)
// AND NOT (next_due_date IS NULL AND EXISTS completion)
// AND is_cancelled = false AND is_archived = false
func IsOverdue(task *models.Task, now time.Time) bool {
@@ -111,20 +113,25 @@ func IsOverdue(task *models.Task, now time.Time) bool {
if effectiveDate == nil {
return false
}
return effectiveDate.Before(now)
// Compare against start of today, not current time
// A task due "today" should not be overdue until tomorrow
startOfDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
return effectiveDate.Before(startOfDay)
}
// IsDueSoon returns true if the task's effective date is within the threshold.
//
// A task is "due soon" when:
// - It has an effective date (NextDueDate or DueDate)
// - That date is >= now AND < (now + daysThreshold)
// - That date is >= start of today AND < start of (today + daysThreshold)
// - The task is not completed, cancelled, archived, or already overdue
//
// Note: Uses start of day for comparisons so tasks due "today" are included.
//
// SQL equivalent (in scopes.go ScopeDueSoon):
//
// COALESCE(next_due_date, due_date) >= ?
// AND COALESCE(next_due_date, due_date) < ?
// COALESCE(next_due_date, due_date) >= DATE_TRUNC('day', ?)
// AND COALESCE(next_due_date, due_date) < DATE_TRUNC('day', ?) + interval 'N days'
// AND NOT (next_due_date IS NULL AND EXISTS completion)
// AND is_cancelled = false AND is_archived = false
func IsDueSoon(task *models.Task, now time.Time, daysThreshold int) bool {
@@ -135,18 +142,22 @@ func IsDueSoon(task *models.Task, now time.Time, daysThreshold int) bool {
if effectiveDate == nil {
return false
}
threshold := now.AddDate(0, 0, daysThreshold)
// Due soon = not overdue AND before threshold
return !effectiveDate.Before(now) && effectiveDate.Before(threshold)
// Use start of day for comparisons
startOfDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
threshold := startOfDay.AddDate(0, 0, daysThreshold)
// Due soon = not overdue (>= start of today) AND before threshold
return !effectiveDate.Before(startOfDay) && effectiveDate.Before(threshold)
}
// IsUpcoming returns true if the task is due after the threshold or has no due date.
//
// A task is "upcoming" when:
// - It has no effective date, OR
// - Its effective date is >= (now + daysThreshold)
// - Its effective date is >= start of (today + daysThreshold)
// - The task is not completed, cancelled, or archived
//
// Note: Uses start of day for comparisons for consistency with other predicates.
//
// This is the default category for tasks that don't match other criteria.
func IsUpcoming(task *models.Task, now time.Time, daysThreshold int) bool {
if !IsActive(task) || IsCompleted(task) {
@@ -156,7 +167,9 @@ func IsUpcoming(task *models.Task, now time.Time, daysThreshold int) bool {
if effectiveDate == nil {
return true // No due date = upcoming
}
threshold := now.AddDate(0, 0, daysThreshold)
// Use start of day for comparisons
startOfDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
threshold := startOfDay.AddDate(0, 0, daysThreshold)
return !effectiveDate.Before(threshold)
}

View File

@@ -187,6 +187,8 @@ func TestIsOverdue(t *testing.T) {
now := time.Now().UTC()
yesterday := now.AddDate(0, 0, -1)
tomorrow := now.AddDate(0, 0, 1)
// Start of today - this is what a DATE column stores (midnight)
startOfToday := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
tests := []struct {
name string
@@ -216,6 +218,17 @@ func TestIsOverdue(t *testing.T) {
now: now,
expected: false,
},
{
name: "not overdue: task due today (start of day)",
task: &models.Task{
NextDueDate: timePtr(startOfToday),
IsCancelled: false,
IsArchived: false,
Completions: []models.TaskCompletion{},
},
now: now, // Current time during the day
expected: false,
},
{
name: "not overdue: cancelled task",
task: &models.Task{
@@ -291,6 +304,8 @@ func TestIsDueSoon(t *testing.T) {
yesterday := now.AddDate(0, 0, -1)
in5Days := now.AddDate(0, 0, 5)
in60Days := now.AddDate(0, 0, 60)
// Start of today - this is what a DATE column stores (midnight)
startOfToday := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
tests := []struct {
name string
@@ -311,6 +326,18 @@ func TestIsDueSoon(t *testing.T) {
daysThreshold: 30,
expected: true,
},
{
name: "due soon: task due today (start of day)",
task: &models.Task{
NextDueDate: timePtr(startOfToday),
IsCancelled: false,
IsArchived: false,
Completions: []models.TaskCompletion{},
},
now: now, // Current time during the day
daysThreshold: 30,
expected: true,
},
{
name: "not due soon: beyond threshold",
task: &models.Task{