making changes to the dependency implementation like those in Commit 57c481e
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user