package service import ( "axolotl/models" "axolotl/store" ) // NodeService is the single entry point for all node operations. // All data-model integrity rules are enforced here; callers cannot produce // invalid state by interacting with this interface alone. type NodeService interface { // Query GetByID(id string) (*models.Node, error) List(filter ListFilter) ([]*models.Node, error) // Lifecycle Add(input AddInput) (*models.Node, error) Update(id string, input UpdateInput) (*models.Node, error) Delete(id string) error // User management AddUser(name string) (*models.Node, error) ListUsers() ([]*models.Node, error) } // AddInput describes a new node to create. type AddInput struct { Title string Content string DueDate string Type string // default: "issue" Status string // default: "open" when Type is "issue" Priority string // Namespace is a namespace name or node ID. Defaults to the current user. Namespace string // Assignee is a username or node ID. Assignee string // Tags are arbitrary user-defined labels (not system properties). Tags []string // Rels are additional typed edges (e.g. blocks, subtask, related). Rels []RelInput } // UpdateInput describes changes to apply to an existing node. // Nil pointer fields mean "no change". type UpdateInput struct { Title *string Content *string DueDate *string // nil = no change; pointer to "" = clear due date // Status "done" is rejected when the node has open blockers. Status *string Priority *string Type *string // Namespace replaces the current namespace. Namespace *string // Assignee replaces the current assignee. Assignee *string AddTags []string RemoveTags []string AddRels []RelInput RemoveRels []RelInput } // ListFilter specifies which nodes to return. Empty fields are ignored. type ListFilter struct { Tags []string Status string Priority string Type string // Namespace filters by namespace name or node ID. Namespace string // Assignee filters by username or node ID. Assignee string // Mention filters to nodes that mention the given username or node ID. Mention string // Rels are additional relation filters (e.g. blocks:someID). Rels []RelInput } // RelInput is a typed, directed edge with a target that may be a name or node ID. type RelInput struct { Type models.RelType Target string // name or node ID; the service resolves names } func InitNodeService(path string) error { return store.InitSQLiteStore(path) } func GetNodeService(cfg Config) (NodeService, error) { st, err := store.FindAndOpenSQLiteStore() if err != nil { return nil, err } return &nodeServiceImpl{store: st, userID: cfg.GetUser()}, nil }