mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 01:36:37 +08:00
fix(zone): register domain delete/update APIs and drop edit UI
补全 Zone 与 Zone 域名的 update/delete 路由与业务逻辑,修复删除域名 404;前端域名列表移除编辑入口,仅保留添加与删除。
This commit is contained in:
@@ -222,6 +222,34 @@ func UpdateDomain(ctx context.Context, zoneID, id uint, input DomainInput) (*mod
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
// DeleteDomain removes a Zone domain that is not bound to a proxy route.
|
||||
func DeleteDomain(ctx context.Context, zoneID, id uint) error {
|
||||
var item model.ZoneDomain
|
||||
if err := db.DB(ctx).Where("id = ? AND zone_id = ?", id, zoneID).First(&item).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if item.ProxyRouteID != nil {
|
||||
return errors.New(errDomainBoundToRoute)
|
||||
}
|
||||
return db.DB(ctx).Delete(&item).Error
|
||||
}
|
||||
|
||||
// Delete removes a Zone that has no remaining domains.
|
||||
func Delete(ctx context.Context, id uint) error {
|
||||
var zone model.Zone
|
||||
if err := db.DB(ctx).First(&zone, id).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
var count int64
|
||||
if err := db.DB(ctx).Model(&model.ZoneDomain{}).Where("zone_id = ?", id).Count(&count).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
return errors.New(errZoneHasDomains)
|
||||
}
|
||||
return db.DB(ctx).Delete(&zone).Error
|
||||
}
|
||||
|
||||
func isUnique(err error) bool {
|
||||
return errors.Is(err, gorm.ErrDuplicatedKey) || strings.Contains(strings.ToLower(err.Error()), "unique constraint")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user