fix: correct GetProperty bug, init to use .ax/, add default aliases, split e2e tests, add due date tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+37
-2
@@ -1,15 +1,48 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Date is a date-only time value that marshals as "YYYY-MM-DD" in JSON.
|
||||
type Date struct{ time.Time }
|
||||
|
||||
// ParseDate parses a date string in "YYYY-MM-DD" or RFC3339 format.
|
||||
func ParseDate(s string) (Date, error) {
|
||||
for _, layout := range []string{"2006-01-02", time.RFC3339} {
|
||||
if t, err := time.Parse(layout, s); err == nil {
|
||||
return Date{t.UTC()}, nil
|
||||
}
|
||||
}
|
||||
return Date{}, fmt.Errorf("cannot parse date %q: expected YYYY-MM-DD", s)
|
||||
}
|
||||
|
||||
func (d Date) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(d.Format("2006-01-02"))
|
||||
}
|
||||
|
||||
func (d *Date) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
parsed, err := ParseDate(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*d = parsed
|
||||
return nil
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content,omitempty"`
|
||||
DueDate string `json:"due_date,omitempty"`
|
||||
DueDate *Date `json:"due_date,omitempty"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
@@ -85,7 +118,9 @@ func (n *Node) RemoveRelation(relType RelType, target string) {
|
||||
func (n *Node) GetProperty(k string) string {
|
||||
prefix := "_" + k + "::"
|
||||
for _, t := range n.Tags {
|
||||
return strings.TrimPrefix(t, prefix)
|
||||
if strings.HasPrefix(t, prefix) {
|
||||
return strings.TrimPrefix(t, prefix)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user