2024-08-08 15:38:37 +08:00
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/1Panel-dev/1Panel/core/app/model"
|
|
|
|
"github.com/1Panel-dev/1Panel/core/global"
|
|
|
|
)
|
|
|
|
|
|
|
|
type BackupRepo struct{}
|
|
|
|
|
|
|
|
type IBackupRepo interface {
|
|
|
|
Get(opts ...DBOption) (model.BackupAccount, error)
|
|
|
|
List(opts ...DBOption) ([]model.BackupAccount, error)
|
|
|
|
Page(limit, offset int, opts ...DBOption) (int64, []model.BackupAccount, error)
|
|
|
|
Create(backup *model.BackupAccount) error
|
2024-08-09 18:30:39 +08:00
|
|
|
Save(backup *model.BackupAccount) error
|
2024-08-08 15:38:37 +08:00
|
|
|
Delete(opts ...DBOption) error
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIBackupRepo() IBackupRepo {
|
|
|
|
return &BackupRepo{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *BackupRepo) Get(opts ...DBOption) (model.BackupAccount, error) {
|
|
|
|
var backup model.BackupAccount
|
|
|
|
db := global.DB
|
|
|
|
for _, opt := range opts {
|
|
|
|
db = opt(db)
|
|
|
|
}
|
|
|
|
err := db.First(&backup).Error
|
|
|
|
return backup, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *BackupRepo) Page(page, size int, opts ...DBOption) (int64, []model.BackupAccount, error) {
|
|
|
|
var ops []model.BackupAccount
|
|
|
|
db := global.DB.Model(&model.BackupAccount{})
|
|
|
|
for _, opt := range opts {
|
|
|
|
db = opt(db)
|
|
|
|
}
|
|
|
|
count := int64(0)
|
|
|
|
db = db.Count(&count)
|
|
|
|
err := db.Limit(size).Offset(size * (page - 1)).Find(&ops).Error
|
|
|
|
return count, ops, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *BackupRepo) List(opts ...DBOption) ([]model.BackupAccount, error) {
|
|
|
|
var ops []model.BackupAccount
|
|
|
|
db := global.DB.Model(&model.BackupAccount{})
|
|
|
|
for _, opt := range opts {
|
|
|
|
db = opt(db)
|
|
|
|
}
|
|
|
|
err := db.Find(&ops).Error
|
|
|
|
return ops, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *BackupRepo) Create(backup *model.BackupAccount) error {
|
|
|
|
return global.DB.Create(backup).Error
|
|
|
|
}
|
|
|
|
|
2024-08-09 18:30:39 +08:00
|
|
|
func (u *BackupRepo) Save(backup *model.BackupAccount) error {
|
|
|
|
return global.DB.Save(backup).Error
|
2024-08-08 15:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (u *BackupRepo) Delete(opts ...DBOption) error {
|
|
|
|
db := global.DB
|
|
|
|
for _, opt := range opts {
|
|
|
|
db = opt(db)
|
|
|
|
}
|
|
|
|
return db.Delete(&model.BackupAccount{}).Error
|
|
|
|
}
|