mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-11-07 18:27:22 +08:00
feat: 增加更新时候名称校验
This commit is contained in:
parent
0dc38ec10c
commit
1ae02968e6
3 changed files with 27 additions and 2 deletions
|
|
@ -25,6 +25,15 @@ func (w WebsiteDnsAccountRepo) GetFirst(opts ...DBOption) (*model.WebsiteDnsAcco
|
|||
return &account, nil
|
||||
}
|
||||
|
||||
func (w WebsiteDnsAccountRepo) List(opts ...DBOption) ([]model.WebsiteDnsAccount, error) {
|
||||
var accounts []model.WebsiteDnsAccount
|
||||
db := getDb(opts...).Model(&model.WebsiteDnsAccount{})
|
||||
if err := db.Find(&accounts).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
func (w WebsiteDnsAccountRepo) Create(account model.WebsiteDnsAccount) error {
|
||||
return getDb().Create(&account).Error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,12 @@ func (w WebsiteDnsAccountService) Update(update request.WebsiteDnsAccountUpdate)
|
|||
if err != nil {
|
||||
return request.WebsiteDnsAccountUpdate{}, err
|
||||
}
|
||||
|
||||
exists, _ := websiteDnsRepo.List(commonRepo.WithByName(update.Name))
|
||||
for _, exist := range exists {
|
||||
if exist.ID != update.ID {
|
||||
return request.WebsiteDnsAccountUpdate{}, buserr.New(constant.ErrNameIsExist)
|
||||
}
|
||||
}
|
||||
if err := websiteDnsRepo.Save(model.WebsiteDnsAccount{
|
||||
BaseModel: model.BaseModel{
|
||||
ID: update.ID,
|
||||
|
|
|
|||
|
|
@ -3,12 +3,18 @@ package service
|
|||
import (
|
||||
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
||||
"github.com/1Panel-dev/1Panel/backend/app/model"
|
||||
"github.com/1Panel-dev/1Panel/backend/buserr"
|
||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||
)
|
||||
|
||||
type WebsiteGroupService struct {
|
||||
}
|
||||
|
||||
func (w WebsiteGroupService) CreateGroup(create request.WebsiteGroupCreate) error {
|
||||
groups, _ := websiteGroupRepo.GetBy(commonRepo.WithByName(create.Name))
|
||||
if len(groups) > 0 {
|
||||
return buserr.New(constant.ErrNameIsExist)
|
||||
}
|
||||
return websiteGroupRepo.Create(&model.WebsiteGroup{
|
||||
Name: create.Name,
|
||||
})
|
||||
|
|
@ -19,7 +25,6 @@ func (w WebsiteGroupService) GetGroups() ([]model.WebsiteGroup, error) {
|
|||
}
|
||||
|
||||
func (w WebsiteGroupService) UpdateGroup(update request.WebsiteGroupUpdate) error {
|
||||
|
||||
if update.Default {
|
||||
if err := websiteGroupRepo.CancelDefault(); err != nil {
|
||||
return err
|
||||
|
|
@ -32,6 +37,12 @@ func (w WebsiteGroupService) UpdateGroup(update request.WebsiteGroupUpdate) erro
|
|||
Default: true,
|
||||
})
|
||||
} else {
|
||||
exists, _ := websiteGroupRepo.GetBy(commonRepo.WithByName(update.Name))
|
||||
for _, exist := range exists {
|
||||
if exist.ID != update.ID {
|
||||
return buserr.New(constant.ErrNameIsExist)
|
||||
}
|
||||
}
|
||||
return websiteGroupRepo.Save(&model.WebsiteGroup{
|
||||
BaseModel: model.BaseModel{
|
||||
ID: update.ID,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue