1Panel/backend/app/repo/operation_log.go

44 lines
1.0 KiB
Go
Raw Normal View History

2022-08-16 15:30:23 +00:00
package repo
import (
"github.com/1Panel-dev/1Panel/app/model"
"github.com/1Panel-dev/1Panel/global"
)
type OperationRepo struct{}
type IOperationRepo interface {
Create(user *model.OperationLog) error
Page(limit, offset int, opts ...DBOption) (int64, []model.OperationLog, error)
Delete(opts ...DBOption) error
}
func NewIOperationRepo() IOperationRepo {
2022-08-16 15:30:23 +00:00
return &OperationRepo{}
}
func (u *OperationRepo) Create(user *model.OperationLog) error {
return global.DB.Create(user).Error
}
func (u *OperationRepo) Page(page, size int, opts ...DBOption) (int64, []model.OperationLog, error) {
var ops []model.OperationLog
db := global.DB.Model(&model.OperationLog{})
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 *OperationRepo) Delete(opts ...DBOption) error {
db := global.DB
for _, opt := range opts {
db = opt(db)
}
return db.Delete(&model.OperationLog{}).Error
}