Skip to content

Commit

Permalink
Merge pull request #2504 from actiontech/modify_audit_plan_api_define
Browse files Browse the repository at this point in the history
Modify audit plan api define
  • Loading branch information
LordofAvernus authored Jul 31, 2024
2 parents f86024c + be41952 commit 7b6b19a
Show file tree
Hide file tree
Showing 14 changed files with 363 additions and 409 deletions.
6 changes: 3 additions & 3 deletions sqle/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
v1ProjectRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans", v1.GetInstanceAuditPlanOverview)

// audit plan; 智能扫描任务
v1ProjectRouter.DELETE("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_type/", v1.DeleteAuditPlanByType)
v1ProjectRouter.PATCH("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_type/", v1.UpdateAuditPlanStatus)
v1ProjectRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_type/sqls", v1.GetInstanceAuditPlanSQLs) // 弃用
v1ProjectRouter.DELETE("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_id/", v1.DeleteAuditPlanById)
v1ProjectRouter.PATCH("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_id/", v1.UpdateAuditPlanStatus)
v1ProjectRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_id/sqls", v1.GetInstanceAuditPlanSQLs) // 弃用
v1ProjectRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_type/sql_meta", v1.GetInstanceAuditPlanSQLMeta)
v1ProjectRouter.POST("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_type/sql_data", v1.GetInstanceAuditPlanSQLData)
v1ProjectRouter.POST("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans/:audit_plan_type/sql_export", v1.GetInstanceAuditPlanSQLExport)
Expand Down
33 changes: 0 additions & 33 deletions sqle/api/controller/v1/dms_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/actiontech/dms/pkg/dms-common/dmsobject"
"github.com/actiontech/sqle/sqle/api/controller"
"github.com/actiontech/sqle/sqle/common"
dms "github.com/actiontech/sqle/sqle/dms"
"github.com/actiontech/sqle/sqle/model"
"github.com/labstack/echo/v4"
)

Expand Down Expand Up @@ -70,36 +68,5 @@ func (h BeforeDeleteDbService) Handle(ctx context.Context, currentUserId string,
}

func (h AfterUpdateDbService) Handle(ctx context.Context, currentUserId string, instanceIdStr string) error {
instanceId, err := strconv.ParseInt(instanceIdStr, 10, 64)
if err != nil {
return err
}
instance, _, err := dms.GetInstancesById(ctx, instanceIdStr)
if err != nil {
return err
}
s := model.GetStorage()
insAuditPlan, exist, err := s.GetInstanceAuditPlanByInstanceID(instanceId)
if err != nil {
return err
}
if !exist {
return nil
}
if needUpdate := h.isNeedUpdateService(instance, insAuditPlan); needUpdate {
insAuditPlan.Business = instance.Business
err := s.Save(insAuditPlan)
if err != nil {
return err
}
}
return nil
}

func (h AfterUpdateDbService) isNeedUpdateService(instance *model.Instance, insAuditPlan *model.InstanceAuditPlan) bool {
needUpdate := false
if instance.Business != insAuditPlan.Business {
return true
}
return needUpdate
}
11 changes: 9 additions & 2 deletions sqle/api/controller/v1/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"

baseV1 "github.com/actiontech/dms/pkg/dms-common/api/base/v1"
dmsV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
v1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
"github.com/actiontech/sqle/sqle/api/controller"
"github.com/actiontech/sqle/sqle/common"
Expand Down Expand Up @@ -334,6 +335,7 @@ const ( // InstanceTipReqV1.FunctionalModule Enums

type InstanceTipReqV1 struct {
FilterDBType string `json:"filter_db_type" query:"filter_db_type"`
FilterByBusiness string `json:"filter_by_business" query:"filter_by_business"`
FilterWorkflowTemplateId uint32 `json:"filter_workflow_template_id" query:"filter_workflow_template_id"`
FunctionalModule string `json:"functional_module" query:"functional_module" enums:"create_audit_plan,create_workflow,sql_manage,create_optimization" valid:"omitempty,oneof=create_audit_plan create_workflow sql_manage create_optimization"`
}
Expand All @@ -360,6 +362,7 @@ type GetInstanceTipsResV1 struct {
// @Security ApiKeyAuth
// @Param project_name path string true "project name"
// @Param filter_db_type query string false "filter db type"
// @Param filter_by_business query string false "filter by business"
// @Param filter_workflow_template_id query string false "filter workflow template id"
// @Param functional_module query string false "functional module" Enums(create_audit_plan,create_workflow,sql_manage,create_optimization)
// @Success 200 {object} v1.GetInstanceTipsResV1
Expand Down Expand Up @@ -389,8 +392,12 @@ func GetInstanceTips(c echo.Context) error {
operationType = v1.OpPermissionTypeCreateOptimization
default:
}

instances, err := GetCanOperationInstances(c.Request().Context(), user, req.FilterDBType, projectUid, operationType)
dbServiceReq := &dmsV1.ListDBServiceReq{
FilterByBusiness: req.FilterByBusiness,
ProjectUid: projectUid,
FilterByDBType: req.FilterDBType,
}
instances, err := GetCanOperationInstances(c.Request().Context(), user, dbServiceReq, operationType)
if err != nil {
return controller.JSONBaseErrorReq(c, err)
}
Expand Down
Loading

0 comments on commit 7b6b19a

Please sign in to comment.