feat: add due date filters for list command
- --due: show only nodes with a due date set - --due-within N: show only nodes due within N days (includes overdue) Implemented in service layer with post-fetch filtering, threaded through API client and server, and exposed via CLI flags. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type apiClient struct {
|
||||
@@ -78,6 +79,12 @@ func (c *apiClient) List(filter ListFilter) ([]*models.Node, error) {
|
||||
q.Add("rel", string(r.Type)+":"+r.Target)
|
||||
}
|
||||
}
|
||||
if filter.HasDueDate {
|
||||
q.Set("has_due_date", "true")
|
||||
}
|
||||
if filter.DueWithin != nil {
|
||||
q.Set("due_within", strconv.Itoa(*filter.DueWithin))
|
||||
}
|
||||
path := "/nodes"
|
||||
if len(q) > 0 {
|
||||
path += "?" + q.Encode()
|
||||
|
||||
@@ -56,7 +56,9 @@ type UpdateInput struct {
|
||||
// Tag filters (Target == "") match by rel_name prefix.
|
||||
// Edge filters (Target != "") are resolved to node IDs.
|
||||
type ListFilter struct {
|
||||
Rels []RelInput
|
||||
Rels []RelInput
|
||||
HasDueDate bool // when true, only return nodes that have a due date set
|
||||
DueWithin *int // when non-nil, only return nodes due within this many days (includes overdue)
|
||||
}
|
||||
|
||||
// RelInput is a typed, directed rel with a target that may be a name or node ID.
|
||||
|
||||
@@ -234,6 +234,26 @@ func (s *nodeServiceImpl) List(filter ListFilter) ([]*models.Node, error) {
|
||||
result = append(result, n)
|
||||
}
|
||||
}
|
||||
|
||||
if filter.HasDueDate || filter.DueWithin != nil {
|
||||
now := time.Now().UTC().Truncate(24 * time.Hour)
|
||||
filtered := result[:0]
|
||||
for _, n := range result {
|
||||
if n.DueDate == nil {
|
||||
continue
|
||||
}
|
||||
if filter.DueWithin != nil {
|
||||
due := n.DueDate.UTC().Truncate(24 * time.Hour)
|
||||
cutoff := now.AddDate(0, 0, *filter.DueWithin)
|
||||
if due.After(cutoff) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
filtered = append(filtered, n)
|
||||
}
|
||||
result = filtered
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user