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

47 lines
1.0 KiB
Go
Raw Normal View History

2022-10-28 09:04:57 +00:00
package service
import (
2022-12-13 09:20:13 +00:00
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
2022-10-28 09:04:57 +00:00
"github.com/1Panel-dev/1Panel/backend/app/model"
)
type WebsiteGroupService struct {
}
2022-12-13 09:20:13 +00:00
func (w WebsiteGroupService) CreateGroup(create request.WebsiteGroupCreate) error {
return websiteGroupRepo.Create(&model.WebsiteGroup{
2022-10-28 09:04:57 +00:00
Name: create.Name,
})
}
2022-12-13 09:20:13 +00:00
func (w WebsiteGroupService) GetGroups() ([]model.WebsiteGroup, error) {
2022-10-28 09:04:57 +00:00
return websiteGroupRepo.GetBy()
}
2022-12-13 09:20:13 +00:00
func (w WebsiteGroupService) UpdateGroup(update request.WebsiteGroupUpdate) error {
2022-11-25 10:59:49 +00:00
if update.Default {
if err := websiteGroupRepo.CancelDefault(); err != nil {
return err
}
2022-12-13 09:20:13 +00:00
return websiteGroupRepo.Save(&model.WebsiteGroup{
2022-11-25 10:59:49 +00:00
BaseModel: model.BaseModel{
ID: update.ID,
},
Name: update.Name,
Default: true,
})
} else {
2022-12-13 09:20:13 +00:00
return websiteGroupRepo.Save(&model.WebsiteGroup{
2022-11-25 10:59:49 +00:00
BaseModel: model.BaseModel{
ID: update.ID,
},
Name: update.Name,
})
}
2022-10-28 09:04:57 +00:00
}
func (w WebsiteGroupService) DeleteGroup(id uint) error {
return websiteGroupRepo.DeleteBy(commonRepo.WithByID(id))
}