diff --git a/plan/storage/sqlite/task.go b/plan/storage/sqlite/task.go index 25ded29..653482d 100644 --- a/plan/storage/sqlite/task.go +++ b/plan/storage/sqlite/task.go @@ -64,9 +64,18 @@ WHERE id = ?`, id).Scan(&tsk.ID, &tsk.Title, &dateStr, &timeStr, &durStr, &recur } func (t *SqliteTask) FindMany(params storage.TaskListParams) ([]item.Task, error) { - rows, err := t.db.Query(` -SELECT id, title, date, time, duration, recurrer -FROM tasks`) + query := `SELECT id, title, date, time, duration, recurrer FROM tasks WHERE 1=1` + args := []interface{}{} + + if params.Recurrer { + query += ` AND recurrer IS NOT NULL AND recurrer != ''` + } + if !params.Date.IsZero() { + query += ` AND date = ?` + args = append(args, params.Date.String()) + } + + rows, err := t.db.Query(query, args...) if err != nil { return nil, fmt.Errorf("%w: %v", ErrSqliteFailure, err) } @@ -87,9 +96,7 @@ FROM tasks`) tsk.Duration = dur tsk.Recurrer = item.NewRecurrer(recurStr) - if storage.Match(tsk, params) { - tasks = append(tasks, tsk) - } + tasks = append(tasks, tsk) } return tasks, nil