Skip to content

Commit

Permalink
refactor: delete iterations and their sub items together
Browse files Browse the repository at this point in the history
feat: initialize issueService
  • Loading branch information
jing-zhi committed Feb 1, 2024
1 parent 7f5a3bc commit a92cac3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
10 changes: 10 additions & 0 deletions internal/apps/dop/endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ import (
sourcepb "github.com/erda-project/erda-proto-go/core/pipeline/source/pb"
tokenpb "github.com/erda-project/erda-proto-go/core/token/pb"
dwfpb "github.com/erda-project/erda-proto-go/dop/devflowrule/pb"
"github.com/erda-project/erda-proto-go/dop/issue/core/pb"
rulepb "github.com/erda-project/erda-proto-go/dop/rule/pb"
"github.com/erda-project/erda/bundle"
"github.com/erda-project/erda/internal/apps/dop/dao"
"github.com/erda-project/erda/internal/apps/dop/event"
"github.com/erda-project/erda/internal/apps/dop/providers/issue/core"
issuequery "github.com/erda-project/erda/internal/apps/dop/providers/issue/core/query"
issuedao "github.com/erda-project/erda/internal/apps/dop/providers/issue/dao"
"github.com/erda-project/erda/internal/apps/dop/providers/projectpipeline"
Expand Down Expand Up @@ -630,6 +632,7 @@ type Endpoints struct {
namespace *namespace.Namespace
envConfig *environment.EnvConfig
issue *issue.Issue
issueService pb.IssueCoreServiceServer
issueState *issuestate.IssueState
workBench *workbench.Workbench
iteration *iteration.Iteration
Expand Down Expand Up @@ -895,6 +898,13 @@ func WithIssue(issue *issue.Issue) Option {
}
}

// WithIssueService 配置 issueService
func WithIssueService(issueService *core.IssueService) Option {
return func(e *Endpoints) {
e.issueService = issueService
}
}

func WithIssueState(state *issuestate.IssueState) Option {
return func(e *Endpoints) {
e.issueState = state
Expand Down
29 changes: 29 additions & 0 deletions internal/apps/dop/endpoints/iteration.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/erda-project/erda-proto-go/dop/issue/core/pb"
"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/internal/apps/dop/dao"
"github.com/erda-project/erda/internal/apps/dop/services/apierrors"
"github.com/erda-project/erda/internal/pkg/user"
"github.com/erda-project/erda/pkg/common/apis"
"github.com/erda-project/erda/pkg/http/httpserver"
"github.com/erda-project/erda/pkg/http/httpserver/errorresp"
"github.com/erda-project/erda/pkg/strutil"
Expand Down Expand Up @@ -235,6 +237,33 @@ func (e *Endpoints) DeleteIteration(ctx context.Context, r *http.Request, vars m
return errorresp.ErrResp(err)
}

// 检查 iteration 下是否有需求/任务/bug;
issueReq := pb.PagingIssueRequest{
ProjectID: iteration.ProjectID,
IterationID: int64(iterationID),
External: true,
PageNo: 1,
PageSize: 10000,
}
issues, _, err := e.issueQuery.Paging(issueReq)
if err != nil {
return apierrors.ErrDeleteIteration.InternalError(err).ToResp(), nil
}
if len(issues) > 0 {
itemIDs := []string{}
for _, v := range issues {
itemIDs = append(itemIDs, strconv.FormatInt(v.Id, 10))
}
var req = &pb.BatchDeleteIssueRequest{}
req.Ids = itemIDs
req.ProjectID = issues[0].ProjectID
ctx = apis.WithUserIDContext(ctx, identityInfo.UserID)
_, err = e.issueService.BatchDeleteIssues(ctx, req)
if err != nil {
return apierrors.ErrDeleteIteration.InternalError(err).ToResp(), nil
}
}

// delete relation labels
if err = e.db.DeleteLabelRelations(apistructs.LabelTypeIteration, strconv.FormatUint(iterationID, 10), nil); err != nil {
return apierrors.ErrDeleteIteration.InternalError(err).ToResp(), nil
Expand Down
1 change: 1 addition & 0 deletions internal/apps/dop/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ func (p *provider) initEndpoints(db *dao.DBClient) (*endpoints.Endpoints, error)
endpoints.WithNamespace(ns),
endpoints.WithEnvConfig(env),
endpoints.WithIssue(issue),
endpoints.WithIssueService(p.IssueCoreSvc),
endpoints.WithIssueState(issueState),
endpoints.WithIteration(itr),
endpoints.WithPublisher(pub),
Expand Down
22 changes: 0 additions & 22 deletions internal/apps/dop/services/iteration/iteration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package iteration
import (
"github.com/jinzhu/gorm"

"github.com/erda-project/erda-proto-go/dop/issue/core/pb"
"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/internal/apps/dop/dao"
"github.com/erda-project/erda/internal/apps/dop/providers/issue/core/query"
Expand Down Expand Up @@ -159,27 +158,6 @@ func (itr *Iteration) GetByTitle(projectID uint64, title string) (*dao.Iteration

// Delete 删除 iteration
func (itr *Iteration) Delete(id uint64) error {
iteration, err := itr.db.GetIteration(id)
if err != nil {
return err
}

// 检查 iteration 下是否有需求/任务/bug; 若有,不可删除
issueReq := pb.PagingIssueRequest{
ProjectID: iteration.ProjectID,
IterationID: int64(id),
External: true,
PageNo: 1,
PageSize: 1,
}
issues, _, err := itr.issue.Paging(issueReq)
if err != nil {
return err
}
if len(issues) > 0 {
return apierrors.ErrDeleteIteration.InvalidParameter("该迭代下存在事件,请先删除事件后再删除迭代")
}

if err := itr.db.DeleteIteration(id); err != nil {
return apierrors.ErrDeleteIteration.InternalError(err)
}
Expand Down

0 comments on commit a92cac3

Please sign in to comment.