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

93 lines
2.5 KiB
Go
Raw Normal View History

2022-10-17 01:10:06 +00:00
package repo
import (
2022-10-18 10:39:45 +00:00
"github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/backend/global"
2022-10-17 01:10:06 +00:00
)
type ComposeTemplateRepo struct{}
type IComposeTemplateRepo interface {
Get(opts ...DBOption) (model.ComposeTemplate, error)
List(opts ...DBOption) ([]model.ComposeTemplate, error)
Page(limit, offset int, opts ...DBOption) (int64, []model.ComposeTemplate, error)
Create(compose *model.ComposeTemplate) error
Update(id uint, vars map[string]interface{}) error
Delete(opts ...DBOption) error
2022-12-06 07:06:42 +00:00
CreateRecord(compose *model.Compose) error
DeleteRecord(opts ...DBOption) error
2022-10-17 01:10:06 +00:00
}
func NewIComposeTemplateRepo() IComposeTemplateRepo {
return &ComposeTemplateRepo{}
}
func (u *ComposeTemplateRepo) Get(opts ...DBOption) (model.ComposeTemplate, error) {
var compose model.ComposeTemplate
db := global.DB
for _, opt := range opts {
db = opt(db)
}
err := db.First(&compose).Error
return compose, err
}
func (u *ComposeTemplateRepo) Page(page, size int, opts ...DBOption) (int64, []model.ComposeTemplate, error) {
var users []model.ComposeTemplate
db := global.DB.Model(&model.ComposeTemplate{})
for _, opt := range opts {
db = opt(db)
}
count := int64(0)
db = db.Count(&count)
err := db.Limit(size).Offset(size * (page - 1)).Find(&users).Error
return count, users, err
}
func (u *ComposeTemplateRepo) List(opts ...DBOption) ([]model.ComposeTemplate, error) {
var composes []model.ComposeTemplate
db := global.DB.Model(&model.ComposeTemplate{})
for _, opt := range opts {
db = opt(db)
}
err := db.Find(&composes).Error
return composes, err
}
func (u *ComposeTemplateRepo) Create(compose *model.ComposeTemplate) error {
return global.DB.Create(compose).Error
}
func (u *ComposeTemplateRepo) Update(id uint, vars map[string]interface{}) error {
return global.DB.Model(&model.ComposeTemplate{}).Where("id = ?", id).Updates(vars).Error
}
func (u *ComposeTemplateRepo) Delete(opts ...DBOption) error {
db := global.DB
for _, opt := range opts {
db = opt(db)
}
return db.Delete(&model.ComposeTemplate{}).Error
}
2022-12-06 07:06:42 +00:00
func (u *ComposeTemplateRepo) ListRecord() ([]model.Compose, error) {
var composes []model.Compose
if err := global.DB.Find(&composes).Error; err != nil {
return nil, err
}
return composes, nil
}
func (u *ComposeTemplateRepo) CreateRecord(compose *model.Compose) error {
return global.DB.Create(compose).Error
}
func (u *ComposeTemplateRepo) DeleteRecord(opts ...DBOption) error {
db := global.DB
for _, opt := range opts {
db = opt(db)
}
return db.Delete(&model.Compose{}).Error
}