This is an automated email from the ASF dual-hosted git repository.
mintsweet 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 a85b9faee feat: bp list api supports filtering by type (#5875)
a85b9faee is described below
commit a85b9faee6c1ef73d577800cfd432a39fb2cd5ee
Author: Klesh Wong <[email protected]>
AuthorDate: Tue Aug 15 16:28:44 2023 +0800
feat: bp list api supports filtering by type (#5875)
---
.../pluginhelper/services/blueprint_helper.go | 30 ++++++++++++++++++++++
backend/server/services/blueprint.go | 9 +++----
2 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/backend/helpers/pluginhelper/services/blueprint_helper.go
b/backend/helpers/pluginhelper/services/blueprint_helper.go
index a765f6bdc..33b21180f 100644
--- a/backend/helpers/pluginhelper/services/blueprint_helper.go
+++ b/backend/helpers/pluginhelper/services/blueprint_helper.go
@@ -38,6 +38,7 @@ type GetBlueprintQuery struct {
SkipRecords int
PageSize int
Mode string
+ Type string
}
type BlueprintProjectPairs struct {
@@ -91,6 +92,18 @@ func (b *BlueprintManager) SaveDbBlueprint(blueprint
*models.Blueprint) errors.E
return nil
}
+const (
+ BP_TYPE_ALL = "ALL"
+ BP_TYPE_MANUAL = "MANUAL"
+ BP_TYPE_DAILY = "DAILY"
+ BP_TYPE_WEEKLY = "WEEKLY"
+ BP_TYPE_MONTHLY = "MONTHLY"
+ BP_TYPE_CUSTOM = "CUSTOM"
+ BP_CRON_DAILY = "0 0 * * *"
+ BP_CRON_WEEKLY = "0 0 * * 1"
+ BP_CRON_MONTHLY = "0 0 1 * *"
+)
+
// GetDbBlueprints returns a paginated list of Blueprints based on `query`
func (b *BlueprintManager) GetDbBlueprints(query *GetBlueprintQuery)
([]*models.Blueprint, int64, errors.Error) {
// process query parameters
@@ -100,6 +113,23 @@ func (b *BlueprintManager) GetDbBlueprints(query
*GetBlueprintQuery) ([]*models.
}
if query.IsManual != nil {
clauses = append(clauses, dal.Where("is_manual = ?",
*query.IsManual))
+ } else {
+ switch query.Type {
+ case "", BP_TYPE_ALL:
+ // do nothing
+ case BP_TYPE_MANUAL:
+ clauses = append(clauses, dal.Where("is_manual = ?",
true))
+ case BP_TYPE_DAILY:
+ clauses = append(clauses, dal.Where("is_manual = ? AND
cron_config = ?", false, BP_CRON_DAILY))
+ case BP_TYPE_WEEKLY:
+ clauses = append(clauses, dal.Where("is_manual = ? AND
cron_config = ?", false, BP_CRON_WEEKLY))
+ case BP_TYPE_MONTHLY:
+ clauses = append(clauses, dal.Where("is_manual = ? AND
cron_config = ?", false, BP_CRON_MONTHLY))
+ case BP_TYPE_CUSTOM:
+ clauses = append(clauses, dal.Where("is_manual = ? AND
cron_config NOT IN ?", false, []string{BP_CRON_DAILY, BP_CRON_WEEKLY,
BP_CRON_MONTHLY}))
+ default:
+ return nil, 0, errors.BadInput.New(fmt.Sprintf("invalid
type %s", query.Type))
+ }
}
if query.Label != "" {
clauses = append(clauses,
diff --git a/backend/server/services/blueprint.go
b/backend/server/services/blueprint.go
index 2bc547561..9761b7ab3 100644
--- a/backend/server/services/blueprint.go
+++ b/backend/server/services/blueprint.go
@@ -44,6 +44,8 @@ type BlueprintQuery struct {
Enable *bool `form:"enable,omitempty"`
IsManual *bool `form:"isManual"`
Label string `form:"label"`
+ // isManual must be omitted or `null` for type to take effect
+ Type string `form:"type" enums:"ALL,MANUAL,DAILY,WEEKLY,MONTHLY,CUSTOM"
validate:"oneof=ALL MANUAL DAILY WEEKLY MONTHLY CUSTOM"`
}
type BlueprintJob struct {
@@ -83,17 +85,14 @@ func CreateBlueprint(blueprint *models.Blueprint)
errors.Error {
// GetBlueprints returns a paginated list of Blueprints based on `query`
func GetBlueprints(query *BlueprintQuery) ([]*models.Blueprint, int64,
errors.Error) {
- blueprints, count, err :=
bpManager.GetDbBlueprints(&services.GetBlueprintQuery{
+ return bpManager.GetDbBlueprints(&services.GetBlueprintQuery{
Enable: query.Enable,
IsManual: query.IsManual,
Label: query.Label,
SkipRecords: query.GetSkip(),
PageSize: query.GetPageSize(),
+ Type: query.Type,
})
- if err != nil {
- return nil, 0, errors.Convert(err)
- }
- return blueprints, count, nil
}
// GetBlueprint returns the detail of a given Blueprint ID