From 1d71a5f40ebed4be0d306dbe392967633551b8af Mon Sep 17 00:00:00 2001 From: yangk Date: Wed, 23 Sep 2020 15:51:34 +0800 Subject: [PATCH] added wrong judgement --- api/handler/application_config_group.go | 16 +++++++++++----- db/dao/dao.go | 1 + db/mysql/dao/tenants.go | 12 ++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/api/handler/application_config_group.go b/api/handler/application_config_group.go index 7f3ca2914..84a6dbdb8 100644 --- a/api/handler/application_config_group.go +++ b/api/handler/application_config_group.go @@ -11,14 +11,17 @@ import ( // AddConfigGroup - func (a *ApplicationAction) AddConfigGroup(appID string, req *model.ApplicationConfigGroup) (*model.ApplicationConfigGroupResp, error) { var serviceResp []dbmodel.ServiceConfigGroup + services, err := db.GetManager().TenantServiceDao().GetServicesByServiceIDs(req.ServiceIDs) + if err != nil { + return nil, err + } // Create application configGroup-services - for _, sid := range req.ServiceIDs { - services, _ := db.GetManager().TenantServiceDao().GetServiceByID(sid) + for _, s := range services { serviceConfigGroup := dbmodel.ServiceConfigGroup{ AppID: appID, ConfigGroupName: req.ConfigGroupName, - ServiceID: sid, - ServiceAlias: services.ServiceAlias, + ServiceID: s.ServiceID, + ServiceAlias: s.ServiceAlias, } serviceResp = append(serviceResp, serviceConfigGroup) if err := db.GetManager().AppConfigGroupServiceDao().AddModel(&serviceConfigGroup); err != nil { @@ -57,7 +60,10 @@ func (a *ApplicationAction) AddConfigGroup(appID string, req *model.ApplicationC return nil, err } - appconfig, _ := db.GetManager().AppConfigGroupDao().GetConfigByID(appID, req.ConfigGroupName) + appconfig, err := db.GetManager().AppConfigGroupDao().GetConfigByID(appID, req.ConfigGroupName) + if err != nil { + return nil, err + } var resp *model.ApplicationConfigGroupResp resp = &model.ApplicationConfigGroupResp{ CreateTime: appconfig.CreatedAt, diff --git a/db/dao/dao.go b/db/dao/dao.go index d17588ca8..9687ef698 100644 --- a/db/dao/dao.go +++ b/db/dao/dao.go @@ -123,6 +123,7 @@ type TenantServiceDao interface { GetServicesInfoByAppID(appID string, page, pageSize int) ([]*model.TenantServices, int64, error) CountServiceByAppID(appID string) (int64, error) GetServiceIDsByAppID(appID string) (re []model.ServiceID) + GetServicesByServiceIDs(serviceIDs []string) ([]*model.TenantServices, error) DeleteServiceByServiceID(serviceID string) error GetServiceMemoryByTenantIDs(tenantIDs, serviceIDs []string) (map[string]map[string]interface{}, error) GetServiceMemoryByServiceIDs(serviceIDs []string) (map[string]map[string]interface{}, error) diff --git a/db/mysql/dao/tenants.go b/db/mysql/dao/tenants.go index 058084012..d7f8124c5 100644 --- a/db/mysql/dao/tenants.go +++ b/db/mysql/dao/tenants.go @@ -492,6 +492,18 @@ func (t *TenantServicesDaoImpl) GetServiceIDsByAppID(appID string) (re []model.S return } +//GetServicesByServiceIDs Get Services By ServiceIDs +func (t *TenantServicesDaoImpl) GetServicesByServiceIDs(serviceIDs []string) ([]*model.TenantServices, error) { + var services []*model.TenantServices + if err := t.DB.Where("service_id in (?)", serviceIDs).Find(&services).Error; err != nil { + if err == gorm.ErrRecordNotFound { + return services, nil + } + return nil, err + } + return services, nil +} + //SetTenantServiceStatus SetTenantServiceStatus func (t *TenantServicesDaoImpl) SetTenantServiceStatus(serviceID, status string) error { var service model.TenantServices