diff --git a/api/handler/application_handler.go b/api/handler/application_handler.go index 98b36be28..94eca57e1 100644 --- a/api/handler/application_handler.go +++ b/api/handler/application_handler.go @@ -72,7 +72,7 @@ func (a *ApplicationAction) CreateApp(req *model.Application) (*model.Applicatio return nil, err } if len(req.ServiceIDs) != 0 { - for _,sid := range req.ServiceIDs { + for _, sid := range req.ServiceIDs { if _, err := db.GetManager().TenantServiceDao().GetServiceByID(sid); err != nil { tx.Rollback() return nil, err @@ -93,7 +93,15 @@ func (a *ApplicationAction) CreateApp(req *model.Application) (*model.Applicatio // UpdateApp - func (a *ApplicationAction) UpdateApp(srcApp *dbmodel.Application, req model.UpdateAppRequest) (*dbmodel.Application, error) { - srcApp.AppName = req.AppName + if req.AppName != "" { + srcApp.AppName = req.AppName + } + if req.GovernanceMode != "" { + if !dbmodel.IsGovernanceModeValid(req.GovernanceMode) { + return nil, bcode.NewBadRequest(fmt.Sprintf("governance mode '%s' is valid", req.GovernanceMode)) + } + srcApp.GovernanceMode = req.GovernanceMode + } if err := db.GetManager().ApplicationDao().UpdateModel(srcApp); err != nil { return nil, err } @@ -249,9 +257,9 @@ func (a *ApplicationAction) getDiskUsage(appID string) float64 { return result } -//BatchBindService +// BatchBindService - func (a *ApplicationAction) BatchBindService(appID string, req model.BindServiceRequest) error { - for _,sid := range req.ServiceIDs { + for _, sid := range req.ServiceIDs { if _, err := db.GetManager().TenantServiceDao().GetServiceByID(sid); err != nil { return err } diff --git a/api/model/model.go b/api/model/model.go index abb482421..2fb170a4f 100644 --- a/api/model/model.go +++ b/api/model/model.go @@ -1653,7 +1653,8 @@ type ListServiceResponse struct { // UpdateAppRequest - type UpdateAppRequest struct { - AppName string `json:"app_name" validate:"required"` + AppName string `json:"app_name"` + GovernanceMode string `json:"governance_mode"` } // BindServiceRequest - diff --git a/db/model/application.go b/db/model/application.go index 4d92ffb13..4007c7189 100644 --- a/db/model/application.go +++ b/db/model/application.go @@ -2,18 +2,23 @@ package model const ( // GovernanceModeBuildInServiceMesh means the governance mode is BUILD_IN_SERVICE_MESH - GovernanceModeBuildInServiceMesh = "build_in_service_mesh" + GovernanceModeBuildInServiceMesh = "BUILD_IN_SERVICE_MESH" // GovernanceModeKubernetesNativeService means the governance mode is KUBERNETES_NATIVE_SERVICE - GovernanceModeKubernetesNativeService = "kubernetes_native_service" + GovernanceModeKubernetesNativeService = "KUBERNETES_NATIVE_SERVICE" ) +// IsGovernanceModeValid checks if the governanceMode is valid. +func IsGovernanceModeValid(governanceMode string) bool { + return governanceMode == GovernanceModeBuildInServiceMesh || governanceMode == GovernanceModeKubernetesNativeService +} + // Application - type Application struct { Model AppName string `gorm:"column:app_name" json:"app_name"` AppID string `gorm:"column:app_id" json:"app_id"` TenantID string `gorm:"column:tenant_id" json:"tenant_id"` - GovernanceMode string `gorm:"column:governance_mode;default:'build_in_service_mesh'" json:"governance_mode"` + GovernanceMode string `gorm:"column:governance_mode;default:'BUILD_IN_SERVICE_MESH'" json:"governance_mode"` } // TableName return tableName "application"