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

45 lines
1.3 KiB
Go
Raw Normal View History

2022-10-28 17:04:57 +08:00
package repo
import (
"github.com/1Panel-dev/1Panel/backend/app/model"
2022-11-25 18:59:49 +08:00
"github.com/1Panel-dev/1Panel/backend/global"
2022-10-28 17:04:57 +08:00
"gorm.io/gorm/clause"
)
type WebSiteGroupRepo struct {
}
func (w WebSiteGroupRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebSiteGroup, error) {
var groups []model.WebSiteGroup
db := getDb(opts...).Model(&model.WebSiteGroup{})
count := int64(0)
db = db.Count(&count)
2022-11-25 18:59:49 +08:00
err := db.Limit(size).Offset(size * (page - 1)).Order("`default` desc").Find(&groups).Error
2022-10-28 17:04:57 +08:00
return count, groups, err
}
func (w WebSiteGroupRepo) GetBy(opts ...DBOption) ([]model.WebSiteGroup, error) {
var groups []model.WebSiteGroup
db := getDb(opts...).Model(&model.WebSiteGroup{})
2022-11-25 18:59:49 +08:00
if err := db.Order("`default` desc").Find(&groups).Error; err != nil {
2022-10-28 17:04:57 +08:00
return groups, err
}
return groups, nil
}
func (w WebSiteGroupRepo) Create(app *model.WebSiteGroup) error {
return getDb().Omit(clause.Associations).Create(app).Error
}
func (w WebSiteGroupRepo) Save(app *model.WebSiteGroup) error {
return getDb().Omit(clause.Associations).Save(app).Error
}
func (w WebSiteGroupRepo) DeleteBy(opts ...DBOption) error {
return getDb(opts...).Delete(&model.WebSiteGroup{}).Error
}
2022-11-25 18:59:49 +08:00
func (w WebSiteGroupRepo) CancelDefault() error {
return global.DB.Model(&model.WebSiteGroup{}).Where("`default` = 1").Updates(map[string]interface{}{"default": 0}).Error
}