diff --git a/internal/models/app.go b/internal/models/app.go index 014918a..345d040 100644 --- a/internal/models/app.go +++ b/internal/models/app.go @@ -54,8 +54,7 @@ type IssueService interface { GetIssueComments(ctx context.Context, issueID string) ([]*Comment, error) GetCommentCounts(ctx context.Context, issueIDs []string) (map[string]int, error) - // Dependency management (thin wrappers over beads dependency API) - AddDependency(ctx context.Context, issueID, dependsOnID string, depType DependencyType, actor string) error + AddDependency(ctx context.Context, dep *Dependency, actor string) error RemoveDependency(ctx context.Context, issueID, dependsOnID string, actor string) error GetDependencies(ctx context.Context, issueID string) ([]*Issue, error) GetDependents(ctx context.Context, issueID string) ([]*Issue, error) diff --git a/internal/storage/beads.go b/internal/storage/beads.go index 99b9a34..734e3a1 100644 --- a/internal/storage/beads.go +++ b/internal/storage/beads.go @@ -53,64 +53,3 @@ func (s *BeadsService) DeleteIssues() error { return nil } - -///////////////////////////////////////////////////////////////////////////////////// -// Dependency Management API wrappers over the underlying beads storage API -///////////////////////////////////////////////////////////////////////////////////// -// AddDependency creates a dependency edge between two issues. -// It is a thin wrapper over the underlying beads storage AddDependency API. -func (s *BeadsService) AddDependency(ctx context.Context, issueID, dependsOnID string, depType models.DependencyType, actor string) error { - dep := &beads.Dependency{ - IssueID: issueID, - DependsOnID: dependsOnID, - Type: beads.DependencyType(depType), - } - return s.Storage.AddDependency(ctx, dep, actor) -} - -// RemoveDependency removes a dependency edge between two issues. -func (s *BeadsService) RemoveDependency(ctx context.Context, issueID, dependsOnID string, actor string) error { - return s.Storage.RemoveDependency(ctx, issueID, dependsOnID, actor) -} - -// GetDependencies returns issues that the given issue depends on. -func (s *BeadsService) GetDependencies(ctx context.Context, issueID string) ([]*models.Issue, error) { - issues, err := s.Storage.GetDependencies(ctx, issueID) - if err != nil { - return nil, err - } - if len(issues) == 0 { - return []*models.Issue{}, nil - } - // types.Issue is layout-compatible with models.Issue (alias to beads.Issue), - // so we can return the slice directly as []*models.Issue. - result := make([]*models.Issue, 0, len(issues)) - for _, iss := range issues { - if iss == nil { - continue - } - casted := models.Issue(*iss) - result = append(result, &casted) - } - return result, nil -} - -// GetDependents returns issues that depend on the given issue. -func (s *BeadsService) GetDependents(ctx context.Context, issueID string) ([]*models.Issue, error) { - issues, err := s.Storage.GetDependents(ctx, issueID) - if err != nil { - return nil, err - } - if len(issues) == 0 { - return []*models.Issue{}, nil - } - result := make([]*models.Issue, 0, len(issues)) - for _, iss := range issues { - if iss == nil { - continue - } - casted := models.Issue(*iss) - result = append(result, &casted) - } - return result, nil -} diff --git a/pkg/web/handler/issues.go b/pkg/web/handler/issues.go index 84b3199..1ee923a 100644 --- a/pkg/web/handler/issues.go +++ b/pkg/web/handler/issues.go @@ -298,8 +298,13 @@ func AddDependencyHandler(w http.ResponseWriter, r *http.Request) { } depType := models.DepBlocks + dep := &models.Dependency{ + IssueID: issue.ID, + DependsOnID: dependsOnID, + Type: depType, + } - if err := app.Issues.AddDependency(r.Context(), issue.ID, dependsOnID, depType, "web"); err != nil { + if err := app.Issues.AddDependency(r.Context(), dep, "web"); err != nil { http.Error(w, "Failed to add dependency: "+err.Error(), http.StatusInternalServerError) return }