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