Skip to content

Commit

Permalink
Merge pull request #1188 from actiontech/issue1174
Browse files Browse the repository at this point in the history
Issue1174
  • Loading branch information
HuangWeiCen authored Dec 9, 2022
2 parents 5cb9c21 + 61e44e8 commit 9f45f04
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion sqle/api/controller/v1/audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func CreateAuditPlan(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errProjectNotExist)
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

// check user
Expand Down
2 changes: 1 addition & 1 deletion sqle/api/controller/v1/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func CreateInstance(c echo.Context) error {
}

if !exist {
return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist")))
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

instance := &model.Instance{
Expand Down
6 changes: 4 additions & 2 deletions sqle/api/controller/v1/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
)

var (
errProjectNotExist = errors.New(errors.DataNotExist, fmt.Errorf("project is not exist"))
errProjectNotExist = func(projectName string) error {
return errors.New(errors.DataNotExist, fmt.Errorf("project [%v] is not exist", projectName))
}
)

type GetProjectReqV1 struct {
Expand Down Expand Up @@ -118,7 +120,7 @@ func GetProjectDetailV1(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, fmt.Errorf("project not exist"))
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

return c.JSON(http.StatusOK, GetProjectDetailResV1{
Expand Down
14 changes: 7 additions & 7 deletions sqle/api/controller/v1/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ func CreateProjectRuleTemplate(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName)))
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

_, exist, err = s.GetGlobalAndProjectRuleTemplateByNameAndProjectId(req.Name, project.ID)
Expand Down Expand Up @@ -751,7 +751,7 @@ func UpdateProjectRuleTemplate(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName)))
return controller.JSONBaseErrorReq(c,errProjectNotExist(projectName))
}
template, exist, err := s.GetGlobalAndProjectRuleTemplateByNameAndProjectId(templateName, project.ID)
if err != nil {
Expand Down Expand Up @@ -856,7 +856,7 @@ func GetProjectRuleTemplate(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName)))
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}
templateName := c.Param("rule_template_name")
template, exist, err := s.GetRuleTemplateDetailByNameAndProjectIds([]uint{project.ID}, templateName)
Expand Down Expand Up @@ -919,7 +919,7 @@ func DeleteProjectRuleTemplate(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName)))
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

templateName := c.Param("rule_template_name")
Expand Down Expand Up @@ -993,7 +993,7 @@ func GetProjectRuleTemplates(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName)))
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

limit, offset := controller.GetLimitAndOffset(req.PageIndex, req.PageSize)
Expand Down Expand Up @@ -1063,7 +1063,7 @@ func CloneProjectRuleTemplate(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName)))
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}
exist, err = s.IsRuleTemplateExistFromAnyProject(req.Name)
if err != nil {
Expand Down Expand Up @@ -1152,7 +1152,7 @@ func GetProjectRuleTemplateTips(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errors.New(errors.DataNotExist, fmt.Errorf("project not exist. projectName=%v", projectName)))
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

return getRuleTemplateTips(c, project.ID, req.FilterDBType)
Expand Down
2 changes: 1 addition & 1 deletion sqle/api/controller/v1/sql_whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func CreateAuditWhitelist(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errProjectNotExist)
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

sqlWhitelist := &model.SqlWhitelist{
Expand Down
2 changes: 1 addition & 1 deletion sqle/api/controller/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ func checkMemberCanDelete(userName, projectName string) error {
return err
}
if !exist {
return errors.New(errors.DataNotExist, fmt.Errorf("project not exist"))
return errProjectNotExist(projectName)
}

if len(project.Managers) == 1 && project.Managers[0].ID == user.ID {
Expand Down
14 changes: 7 additions & 7 deletions sqle/api/controller/v1/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func GetWorkflowTemplate(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errProjectNotExist)
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

template, exist, err := s.GetWorkflowTemplateById(project.WorkflowTemplateId)
Expand Down Expand Up @@ -201,7 +201,7 @@ func UpdateWorkflowTemplate(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errProjectNotExist)
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

userName := controller.GetUserName(c)
Expand Down Expand Up @@ -344,7 +344,7 @@ func ApproveWorkflow(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errProjectNotExist)
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

userName := controller.GetUserName(c)
Expand Down Expand Up @@ -446,7 +446,7 @@ func RejectWorkflow(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errProjectNotExist)
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

workflowName := c.Param("workflow_name")
Expand Down Expand Up @@ -533,7 +533,7 @@ func CancelWorkflow(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errProjectNotExist)
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

workflowName := c.Param("workflow_name")
Expand Down Expand Up @@ -949,7 +949,7 @@ func CreateWorkflowV1(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errProjectNotExist)
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

user, err := controller.GetCurrentUser(c)
Expand Down Expand Up @@ -1230,7 +1230,7 @@ func GetWorkflowsV1(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}
if !exist {
return controller.JSONBaseErrorReq(c, errProjectNotExist)
return controller.JSONBaseErrorReq(c, errProjectNotExist(projectName))
}

user, err := controller.GetCurrentUser(c)
Expand Down

0 comments on commit 9f45f04

Please sign in to comment.