2022-10-12 18:57:22 +08:00
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-10-17 16:32:31 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
2022-10-12 18:57:22 +08:00
|
|
|
"gorm.io/gorm"
|
|
|
|
"gorm.io/gorm/clause"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AppInstallBackupRepo struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a AppInstallBackupRepo) WithAppInstallID(appInstallID uint) DBOption {
|
|
|
|
return func(db *gorm.DB) *gorm.DB {
|
|
|
|
return db.Where("app_install_id = ?", appInstallID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a AppInstallBackupRepo) Create(ctx context.Context, backup model.AppInstallBackup) error {
|
|
|
|
return getTx(ctx).Omit(clause.Associations).Create(&backup).Error
|
|
|
|
}
|
|
|
|
|
2022-10-17 16:32:31 +08:00
|
|
|
func (a AppInstallBackupRepo) Delete(ctx context.Context, opts ...DBOption) error {
|
|
|
|
return getTx(ctx, opts...).Omit(clause.Associations).Delete(&model.AppInstallBackup{}).Error
|
2022-10-12 18:57:22 +08:00
|
|
|
}
|
2022-10-17 16:32:31 +08:00
|
|
|
|
2022-10-12 18:57:22 +08:00
|
|
|
func (a AppInstallBackupRepo) GetBy(opts ...DBOption) ([]model.AppInstallBackup, error) {
|
|
|
|
var backups []model.AppInstallBackup
|
2022-10-17 16:32:31 +08:00
|
|
|
if err := getDb(opts...).Preload("AppDetail").Find(&backups); err != nil {
|
2022-10-12 18:57:22 +08:00
|
|
|
return backups, nil
|
|
|
|
}
|
|
|
|
return backups, nil
|
|
|
|
}
|
|
|
|
|
2022-10-13 16:46:38 +08:00
|
|
|
func (a AppInstallBackupRepo) GetFirst(opts ...DBOption) (model.AppInstallBackup, error) {
|
|
|
|
var backup model.AppInstallBackup
|
|
|
|
db := getDb(opts...).Model(&model.AppInstallBackup{})
|
2022-10-17 16:32:31 +08:00
|
|
|
err := db.Preload("AppDetail").First(&backup).Error
|
2022-10-13 16:46:38 +08:00
|
|
|
return backup, err
|
|
|
|
}
|
|
|
|
|
2022-10-12 18:57:22 +08:00
|
|
|
func (a AppInstallBackupRepo) Page(page, size int, opts ...DBOption) (int64, []model.AppInstallBackup, error) {
|
|
|
|
var backups []model.AppInstallBackup
|
|
|
|
db := getDb(opts...).Model(&model.AppInstallBackup{})
|
|
|
|
count := int64(0)
|
|
|
|
db = db.Count(&count)
|
2022-10-17 16:32:31 +08:00
|
|
|
err := db.Limit(size).Offset(size * (page - 1)).Preload("AppDetail").Find(&backups).Error
|
2022-10-12 18:57:22 +08:00
|
|
|
return count, backups, err
|
|
|
|
}
|