mirror of
				https://github.com/1Panel-dev/1Panel.git
				synced 2025-10-31 19:26:02 +08:00 
			
		
		
		
	fix: 网站,一键部署没有过滤已经关联了网站的应用的 BUG
This commit is contained in:
		
							parent
							
								
									c05d669c5f
								
							
						
					
					
						commit
						53ac95b005
					
				
					 2 changed files with 21 additions and 17 deletions
				
			
		|  | @ -10,50 +10,56 @@ import ( | |||
| 
 | ||||
| type AppInstallRepo struct{} | ||||
| 
 | ||||
| func (a AppInstallRepo) WithDetailIdsIn(detailIds []uint) DBOption { | ||||
| func (a *AppInstallRepo) WithDetailIdsIn(detailIds []uint) DBOption { | ||||
| 	return func(g *gorm.DB) *gorm.DB { | ||||
| 		return g.Where("app_detail_id in (?)", detailIds) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) WithDetailIdNotIn(detailIds []uint) DBOption { | ||||
| func (a *AppInstallRepo) WithDetailIdNotIn(detailIds []uint) DBOption { | ||||
| 	return func(g *gorm.DB) *gorm.DB { | ||||
| 		return g.Where("app_detail_id not in (?)", detailIds) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) WithAppId(appId uint) DBOption { | ||||
| func (a *AppInstallRepo) WithAppId(appId uint) DBOption { | ||||
| 	return func(g *gorm.DB) *gorm.DB { | ||||
| 		return g.Where("app_id = ?", appId) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) WithAppIdsIn(appIds []uint) DBOption { | ||||
| func (a *AppInstallRepo) WithAppIdsIn(appIds []uint) DBOption { | ||||
| 	return func(g *gorm.DB) *gorm.DB { | ||||
| 		return g.Where("app_id in (?)", appIds) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) WithStatus(status string) DBOption { | ||||
| func (a *AppInstallRepo) WithStatus(status string) DBOption { | ||||
| 	return func(g *gorm.DB) *gorm.DB { | ||||
| 		return g.Where("status = ?", status) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) WithServiceName(serviceName string) DBOption { | ||||
| func (a *AppInstallRepo) WithServiceName(serviceName string) DBOption { | ||||
| 	return func(db *gorm.DB) *gorm.DB { | ||||
| 		return db.Where("service_name = ?", serviceName) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) GetBy(opts ...DBOption) ([]model.AppInstall, error) { | ||||
| func (a *AppInstallRepo) WithIdNotInWebsite() DBOption { | ||||
| 	return func(db *gorm.DB) *gorm.DB { | ||||
| 		return db.Where("id not in (select app_install_id from websites)") | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (a *AppInstallRepo) GetBy(opts ...DBOption) ([]model.AppInstall, error) { | ||||
| 	var install []model.AppInstall | ||||
| 	db := getDb(opts...).Model(&model.AppInstall{}) | ||||
| 	err := db.Preload("App").Preload("Backups").Find(&install).Error | ||||
| 	return install, err | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) GetFirst(opts ...DBOption) (model.AppInstall, error) { | ||||
| func (a *AppInstallRepo) GetFirst(opts ...DBOption) (model.AppInstall, error) { | ||||
| 	var install model.AppInstall | ||||
| 	db := getDb(opts...).Model(&model.AppInstall{}) | ||||
| 	err := db.Preload("App").Preload("Backups", func(db *gorm.DB) *gorm.DB { | ||||
|  | @ -63,25 +69,25 @@ func (a AppInstallRepo) GetFirst(opts ...DBOption) (model.AppInstall, error) { | |||
| 	return install, err | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) Create(ctx context.Context, install *model.AppInstall) error { | ||||
| func (a *AppInstallRepo) Create(ctx context.Context, install *model.AppInstall) error { | ||||
| 	db := getTx(ctx).Model(&model.AppInstall{}) | ||||
| 	return db.Create(&install).Error | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) Save(install *model.AppInstall) error { | ||||
| func (a *AppInstallRepo) Save(install *model.AppInstall) error { | ||||
| 	return getDb().Save(&install).Error | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) DeleteBy(opts ...DBOption) error { | ||||
| func (a *AppInstallRepo) DeleteBy(opts ...DBOption) error { | ||||
| 	return getDb(opts...).Delete(&model.AppInstall{}).Error | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) Delete(ctx context.Context, install model.AppInstall) error { | ||||
| func (a *AppInstallRepo) Delete(ctx context.Context, install model.AppInstall) error { | ||||
| 	db := getTx(ctx).Model(&model.AppInstall{}) | ||||
| 	return db.Delete(&install).Error | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) Page(page, size int, opts ...DBOption) (int64, []model.AppInstall, error) { | ||||
| func (a *AppInstallRepo) Page(page, size int, opts ...DBOption) (int64, []model.AppInstall, error) { | ||||
| 	var apps []model.AppInstall | ||||
| 	db := getDb(opts...).Model(&model.AppInstall{}) | ||||
| 	count := int64(0) | ||||
|  | @ -90,7 +96,7 @@ func (a AppInstallRepo) Page(page, size int, opts ...DBOption) (int64, []model.A | |||
| 	return count, apps, err | ||||
| } | ||||
| 
 | ||||
| func (a AppInstallRepo) BatchUpdateBy(maps map[string]interface{}, opts ...DBOption) error { | ||||
| func (a *AppInstallRepo) BatchUpdateBy(maps map[string]interface{}, opts ...DBOption) error { | ||||
| 	db := getDb(opts...).Model(&model.AppInstall{}) | ||||
| 	if len(opts) == 0 { | ||||
| 		db = db.Where("1=1") | ||||
|  |  | |||
|  | @ -50,7 +50,6 @@ func (a AppInstallService) Page(req request.AppInstalledSearch) (int64, []respon | |||
| } | ||||
| 
 | ||||
| func (a AppInstallService) CheckExist(key string) (*response.AppInstalledCheck, error) { | ||||
| 
 | ||||
| 	res := &response.AppInstalledCheck{ | ||||
| 		IsExist: false, | ||||
| 	} | ||||
|  | @ -101,7 +100,7 @@ func (a AppInstallService) Search(req request.AppInstalledSearch) ([]response.Ap | |||
| 		for _, app := range apps { | ||||
| 			ids = append(ids, app.ID) | ||||
| 		} | ||||
| 		installs, err = appInstallRepo.GetBy(appInstallRepo.WithAppIdsIn(ids)) | ||||
| 		installs, err = appInstallRepo.GetBy(appInstallRepo.WithAppIdsIn(ids), appInstallRepo.WithIdNotInWebsite()) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
|  | @ -191,7 +190,6 @@ func (a AppInstallService) PageInstallBackups(req request.AppBackupSearch) (int6 | |||
| } | ||||
| 
 | ||||
| func (a AppInstallService) DeleteBackup(req request.AppBackupDelete) error { | ||||
| 
 | ||||
| 	backups, err := appInstallBackupRepo.GetBy(commonRepo.WithIdsIn(req.Ids)) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue