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 (
2022-12-13 17:20:13 +08:00
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
2022-10-28 17:04:57 +08:00
"github.com/1Panel-dev/1Panel/backend/app/model"
)
type WebsiteGroupService struct {
}
2022-12-13 17:20:13 +08:00
func (w WebsiteGroupService) CreateGroup(create request.WebsiteGroupCreate) error {
return websiteGroupRepo.Create(&model.WebsiteGroup{
2022-10-28 17:04:57 +08:00
Name: create.Name,
})
}
2022-12-13 17:20:13 +08:00
func (w WebsiteGroupService) GetGroups() ([]model.WebsiteGroup, error) {
2022-10-28 17:04:57 +08:00
return websiteGroupRepo.GetBy()
}
2022-12-13 17:20:13 +08:00
func (w WebsiteGroupService) UpdateGroup(update request.WebsiteGroupUpdate) error {
2022-11-25 18:59:49 +08:00
if update.Default {
if err := websiteGroupRepo.CancelDefault(); err != nil {
return err
}
2022-12-13 17:20:13 +08:00
return websiteGroupRepo.Save(&model.WebsiteGroup{
2022-11-25 18:59:49 +08:00
BaseModel: model.BaseModel{
ID: update.ID,
},
Name: update.Name,
Default: true,
})
} else {
2022-12-13 17:20:13 +08:00
return websiteGroupRepo.Save(&model.WebsiteGroup{
2022-11-25 18:59:49 +08:00
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))
}