This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new a7556dd7 feat: api to get pipeline list of blueprints by blueprint_id
(#2722)
a7556dd7 is described below
commit a7556dd7815ed0e06769a6677fc023e89c917ddb
Author: abeizn <[email protected]>
AuthorDate: Thu Aug 11 22:06:19 2022 +0800
feat: api to get pipeline list of blueprints by blueprint_id (#2722)
* feat: api to get pipeline list of blueprints by blueprint_id
* feat: api to get pipeline list of blueprints by blueprint_id
* feat: api to get pipeline list of blueprints by blueprint_id
* feat: api to get pipeline list of blueprints by blueprint_id
* feat: api to get pipeline list of blueprints by blueprint_id
---
api/blueprints/blueprints.go | 27 ++++++++++++++++++++++++++-
api/pipelines/pipelines.go | 11 ++---------
api/router.go | 1 +
api/shared/api_output.go | 6 ++++++
services/pipeline.go | 12 ++++++++----
5 files changed, 43 insertions(+), 14 deletions(-)
diff --git a/api/blueprints/blueprints.go b/api/blueprints/blueprints.go
index c915eabe..dc1bd9ed 100644
--- a/api/blueprints/blueprints.go
+++ b/api/blueprints/blueprints.go
@@ -22,7 +22,6 @@ import (
"strconv"
"github.com/apache/incubator-devlake/api/shared"
-
"github.com/apache/incubator-devlake/models"
"github.com/apache/incubator-devlake/services"
"github.com/gin-gonic/gin"
@@ -201,3 +200,29 @@ func Trigger(c *gin.Context) {
}
shared.ApiOutputSuccess(c, pipeline, http.StatusOK)
}
+
+// @Summary get pipelines by blueprint id
+// @Description get pipelines by blueprint id
+// @Tags framework/blueprints
+// @Accept application/json
+// @Param blueprintId path int true "blueprint id"
+// @Success 200 {object} shared.ResponsePipelines
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 500 {string} errcode.Error "Internel Error"
+// @Router /blueprints/{blueprintId}/pipelines [get]
+func GetBlueprintPipelines(c *gin.Context) {
+ blueprintId := c.Param("blueprintId")
+ id, err := strconv.ParseUint(blueprintId, 10, 64)
+ if err != nil {
+ shared.ApiOutputError(c, err, http.StatusBadRequest)
+ return
+ }
+ var query services.PipelineQuery
+ query.BlueprintId = id
+ pipelines, count, err := services.GetPipelines(&query)
+ if err != nil {
+ shared.ApiOutputError(c, err, http.StatusBadRequest)
+ return
+ }
+ shared.ApiOutputSuccess(c, shared.ResponsePipelines{Pipelines:
pipelines, Count: count}, http.StatusOK)
+}
diff --git a/api/pipelines/pipelines.go b/api/pipelines/pipelines.go
index bae0dfc8..d5a5ab2c 100644
--- a/api/pipelines/pipelines.go
+++ b/api/pipelines/pipelines.go
@@ -87,19 +87,12 @@ GET
/pipelines?status=TASK_RUNNING&pending=1&page=1&pagesize=10
// @Summary Get list of pipelines
// @Description GET /pipelines?status=TASK_RUNNING&pending=1&page=1&pagesize=10
-// @Description RETURN SAMPLE
-// @Description {
-// @Description "pipelines": [
-// @Description {"id": 1, "name": "test-pipeline", ...}
-// @Description ],
-// @Description "count": 5
-// @Description }
// @Tags framework/pipelines
// @Param status query string true "query"
// @Param pending query int true "query"
// @Param page query int true "query"
// @Param pagesize query int true "query"
-// @Success 200 {object} models.Pipeline
+// @Success 200 {object} shared.ResponsePipelines
// @Failure 400 {string} errcode.Error "Bad Request"
// @Failure 500 {string} errcode.Error "Internel Error"
// @Router /pipelines [get]
@@ -115,7 +108,7 @@ func Index(c *gin.Context) {
shared.ApiOutputError(c, err, http.StatusBadRequest)
return
}
- shared.ApiOutputSuccess(c, gin.H{"pipelines": pipelines, "count":
count}, http.StatusOK)
+ shared.ApiOutputSuccess(c, shared.ResponsePipelines{Pipelines:
pipelines, Count: count}, http.StatusOK)
}
/*
diff --git a/api/router.go b/api/router.go
index d99fba7c..84767c1e 100644
--- a/api/router.go
+++ b/api/router.go
@@ -46,6 +46,7 @@ func RegisterRouter(r *gin.Engine) {
r.GET("/blueprints", blueprints.Index)
r.POST("/blueprints", blueprints.Post)
r.GET("/blueprints/:blueprintId", blueprints.Get)
+ r.GET("/blueprints/:blueprintId/pipelines",
blueprints.GetBlueprintPipelines)
r.DELETE("/pipelines/:pipelineId", pipelines.Delete)
r.GET("/pipelines/:pipelineId/tasks", task.Index)
diff --git a/api/shared/api_output.go b/api/shared/api_output.go
index 28e2e630..871ba804 100644
--- a/api/shared/api_output.go
+++ b/api/shared/api_output.go
@@ -20,6 +20,7 @@ package shared
import (
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/logger"
+ "github.com/apache/incubator-devlake/models"
"github.com/gin-gonic/gin"
)
@@ -28,6 +29,11 @@ type ApiBody struct {
Message string `json:"message"`
}
+type ResponsePipelines struct {
+ Count int64 `json:"count"`
+ Pipelines []*models.Pipeline `json:"pipelines"`
+}
+
func ApiOutputError(c *gin.Context, err error, status int) {
if e, ok := err.(*errors.Error); ok {
c.JSON(e.Status, &ApiBody{
diff --git a/services/pipeline.go b/services/pipeline.go
index 469f92ef..38c96e07 100644
--- a/services/pipeline.go
+++ b/services/pipeline.go
@@ -42,10 +42,11 @@ var pipelineLog = logger.Global.Nested("pipeline service")
// PipelineQuery FIXME ...
type PipelineQuery struct {
- Status string `form:"status"`
- Pending int `form:"pending"`
- Page int `form:"page"`
- PageSize int `form:"pageSize"`
+ Status string `form:"status"`
+ Pending int `form:"pending"`
+ Page int `form:"page"`
+ PageSize int `form:"pageSize"`
+ BlueprintId uint64 `form:"blueprint_id"`
}
func pipelineServiceInit() {
@@ -160,6 +161,9 @@ func CreatePipeline(newPipeline *models.NewPipeline)
(*models.Pipeline, error) {
func GetPipelines(query *PipelineQuery) ([]*models.Pipeline, int64, error) {
pipelines := make([]*models.Pipeline, 0)
db := db.Model(pipelines).Order("id DESC")
+ if query.BlueprintId != 0 {
+ db = db.Where("blueprint_id = ?", query.BlueprintId)
+ }
if query.Status != "" {
db = db.Where("status = ?", query.Status)
}