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

47 lines
1.0 KiB
Go
Raw Normal View History

2022-10-28 17:04:57 +08:00
package service
import (
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/model"
)
type WebsiteGroupService struct {
}
2022-11-02 15:19:14 +08:00
func (w WebsiteGroupService) CreateGroup(create dto.WebSiteGroupCreate) error {
2022-10-28 17:04:57 +08:00
return websiteGroupRepo.Create(&model.WebSiteGroup{
Name: create.Name,
})
}
func (w WebsiteGroupService) GetGroups() ([]model.WebSiteGroup, error) {
return websiteGroupRepo.GetBy()
}
2022-11-02 15:19:14 +08:00
func (w WebsiteGroupService) UpdateGroup(update dto.WebSiteGroupUpdate) error {
2022-11-25 18:59:49 +08:00
if update.Default {
if err := websiteGroupRepo.CancelDefault(); err != nil {
return err
}
return websiteGroupRepo.Save(&model.WebSiteGroup{
BaseModel: model.BaseModel{
ID: update.ID,
},
Name: update.Name,
Default: true,
})
} else {
return websiteGroupRepo.Save(&model.WebSiteGroup{
BaseModel: model.BaseModel{
ID: update.ID,
},
Name: update.Name,
})
}
2022-10-28 17:04:57 +08:00
}
func (w WebsiteGroupService) DeleteGroup(id uint) error {
return websiteGroupRepo.DeleteBy(commonRepo.WithByID(id))
}