2022-09-16 18:53:45 +08:00
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
2022-10-17 16:32:31 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
2022-09-16 18:53:45 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type BackupRepo struct{}
|
|
|
|
|
|
|
|
type IBackupRepo interface {
|
2022-09-19 19:42:06 +08:00
|
|
|
Get(opts ...DBOption) (model.BackupAccount, error)
|
|
|
|
List(opts ...DBOption) ([]model.BackupAccount, error)
|
2022-09-16 18:53:45 +08:00
|
|
|
Create(backup *model.BackupAccount) error
|
|
|
|
Update(id uint, vars map[string]interface{}) error
|
|
|
|
Delete(opts ...DBOption) error
|
|
|
|
}
|
|
|
|
|
2022-09-26 18:40:00 +08:00
|
|
|
func NewIBackupRepo() IBackupRepo {
|
2022-09-16 18:53:45 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-09-19 19:42:06 +08:00
|
|
|
func (u *BackupRepo) List(opts ...DBOption) ([]model.BackupAccount, error) {
|
2022-09-16 18:53:45 +08:00
|
|
|
var ops []model.BackupAccount
|
|
|
|
db := global.DB.Model(&model.BackupAccount{})
|
|
|
|
for _, opt := range opts {
|
|
|
|
db = opt(db)
|
|
|
|
}
|
|
|
|
count := int64(0)
|
|
|
|
db = db.Count(&count)
|
2022-09-19 19:42:06 +08:00
|
|
|
err := db.Find(&ops).Error
|
|
|
|
return ops, err
|
2022-09-16 18:53:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (u *BackupRepo) Create(backup *model.BackupAccount) error {
|
|
|
|
return global.DB.Create(backup).Error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *BackupRepo) Update(id uint, vars map[string]interface{}) error {
|
|
|
|
return global.DB.Model(&model.BackupAccount{}).Where("id = ?", id).Updates(vars).Error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *BackupRepo) Delete(opts ...DBOption) error {
|
|
|
|
db := global.DB
|
|
|
|
for _, opt := range opts {
|
|
|
|
db = opt(db)
|
|
|
|
}
|
|
|
|
return db.Delete(&model.BackupAccount{}).Error
|
|
|
|
}
|