mirror of https://github.com/1Panel-dev/1Panel
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
2 years ago
|
package repo
|
||
|
|
||
|
import (
|
||
|
"github.com/1Panel-dev/1Panel/app/model"
|
||
|
"github.com/1Panel-dev/1Panel/global"
|
||
|
)
|
||
|
|
||
|
type GroupRepo struct{}
|
||
|
|
||
|
type IGroupRepo interface {
|
||
|
Get(opts ...DBOption) (model.Group, error)
|
||
|
GetList(opts ...DBOption) ([]model.Group, error)
|
||
|
Create(group *model.Group) error
|
||
|
Update(id uint, vars map[string]interface{}) error
|
||
|
Delete(opts ...DBOption) error
|
||
|
}
|
||
|
|
||
|
func NewIGroupService() IGroupRepo {
|
||
|
return &GroupRepo{}
|
||
|
}
|
||
|
|
||
|
func (u *GroupRepo) Get(opts ...DBOption) (model.Group, error) {
|
||
|
var group model.Group
|
||
|
db := global.DB
|
||
|
for _, opt := range opts {
|
||
|
db = opt(db)
|
||
|
}
|
||
|
err := db.First(&group).Error
|
||
|
return group, err
|
||
|
}
|
||
|
|
||
|
func (u *GroupRepo) GetList(opts ...DBOption) ([]model.Group, error) {
|
||
|
var groups []model.Group
|
||
|
db := global.DB.Model(&model.Group{})
|
||
|
for _, opt := range opts {
|
||
|
db = opt(db)
|
||
|
}
|
||
|
err := db.Find(&groups).Error
|
||
|
return groups, err
|
||
|
}
|
||
|
|
||
|
func (u *GroupRepo) Create(group *model.Group) error {
|
||
|
return global.DB.Create(group).Error
|
||
|
}
|
||
|
|
||
|
func (u *GroupRepo) Update(id uint, vars map[string]interface{}) error {
|
||
|
return global.DB.Model(&model.Group{}).Where("id = ?", id).Updates(vars).Error
|
||
|
}
|
||
|
|
||
|
func (u *GroupRepo) Delete(opts ...DBOption) error {
|
||
|
db := global.DB
|
||
|
for _, opt := range opts {
|
||
|
db = opt(db)
|
||
|
}
|
||
|
return db.Delete(&model.Group{}).Error
|
||
|
}
|