Skip to content

Implement NodeService with CRUD operations #104

Closed

Description

@malibio

Overview

Implement the core NodeService with CRUD operations for Text, Task, and Date nodes (initial E2E testing scope).

Scope: Text/Task/Date Nodes Only

This issue focuses on getting Text, Task, and Date nodes working end-to-end first. Person and Project node support will be added in separate issues after E2E testing is complete.

Implementation Tasks

  • Create NodeService struct with DatabaseService and behavior registry
  • Implement basic CRUD operations (create, read, update, delete)
  • Add hierarchy operations (get_children, move_node, reorder_siblings)
  • Implement node validation using behavior registry (Text, Task, Date behaviors)
  • Add bulk operations for efficiency
  • Create comprehensive error handling
  • Add transaction support for complex operations

Acceptance Criteria

  • NodeService integrates with DatabaseService (from Set up database connection with libsql #101)
  • NodeService provides type-safe CRUD operations
  • Node creation validates using TextNodeBehavior, TaskNodeBehavior, or DateNodeBehavior
  • Hierarchy operations maintain data consistency
  • Sibling ordering works with before_sibling_id pointer
  • Bulk operations handle large datasets efficiently
  • Database transactions ensure data integrity
  • Error handling provides detailed context
  • All operations are async and thread-safe
  • Comprehensive unit tests cover Text/Task/Date node operations

Technical Specifications

Service Structure:
```rust
use crate::db::DatabaseService;
use crate::behaviors::NodeBehaviorRegistry;

pub struct NodeService {
db: Arc,
behaviors: Arc,
}

impl NodeService {
pub async fn new(db: DatabaseService) -> Result<Self, Error>;
pub async fn create_node(&self, node: Node) -> Result<String, Error>;
pub async fn get_node(&self, id: &str) -> Result<Option, Error>;
pub async fn update_node(&self, id: &str, update: NodeUpdate) -> Result<(), Error>;
pub async fn delete_node(&self, id: &str) -> Result<(), Error>;
pub async fn get_children(&self, parent_id: &str) -> Result<Vec, Error>;
pub async fn move_node(&self, node_id: &str, new_parent: Option<&str>) -> Result<(), Error>;
}
```

Key Features:

  • Uses libsql (NOT sqlx) via DatabaseService
  • Behavior validation before database operations (Text, Task, Date only for now)
  • Hierarchy consistency checks
  • Efficient bulk operations
  • Transaction support for complex operations
  • Pure JSON schema queries (properties JSON field)

Test Coverage:

  • Text node creation, update, delete
  • Task node with status/priority validation
  • Date node with YYYY-MM-DD validation
  • Hierarchy operations (parent/child relationships)
  • Sibling ordering with before_sibling_id

Related Issues

This provides the foundation for Text/Task/Date E2E testing before expanding to other node types.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions