增加删除/恢复DNS域名API

This commit is contained in:
GoEdgeLab
2021-11-06 16:23:12 +08:00
parent 5a7e3c265f
commit 1f9e3e428b
3 changed files with 35 additions and 6 deletions

View File

@@ -263,7 +263,6 @@ func (this *DNSDomainDAO) ExistDomainRecord(tx *dbs.Tx, domainId int64, recordNa
func (this *DNSDomainDAO) FindEnabledDomainWithName(tx *dbs.Tx, providerId int64, domainName string) (*DNSDomain, error) { func (this *DNSDomainDAO) FindEnabledDomainWithName(tx *dbs.Tx, providerId int64, domainName string) (*DNSDomain, error) {
one, err := this.Query(tx). one, err := this.Query(tx).
State(DNSDomainStateEnabled). State(DNSDomainStateEnabled).
Attr("isOn", true).
Attr("providerId", providerId). Attr("providerId", providerId).
Attr("name", domainName). Attr("name", domainName).
Find() Find()
@@ -280,3 +279,11 @@ func (this *DNSDomainDAO) UpdateDomainIsUp(tx *dbs.Tx, domainId int64, isUp bool
Set("isUp", isUp). Set("isUp", isUp).
UpdateQuickly() UpdateQuickly()
} }
// UpdateDomainIsDeleted 设置域名为删除
func (this *DNSDomainDAO) UpdateDomainIsDeleted(tx *dbs.Tx, domainId int64, isDeleted bool) error {
return this.Query(tx).
Pk(domainId).
Set("isDeleted", isDeleted).
UpdateQuickly()
}

View File

@@ -16,6 +16,7 @@ type DNSDomain struct {
Routes string `field:"routes"` // 线路数据 Routes string `field:"routes"` // 线路数据
IsUp uint8 `field:"isUp"` // 是否在线 IsUp uint8 `field:"isUp"` // 是否在线
State uint8 `field:"state"` // 状态 State uint8 `field:"state"` // 状态
IsDeleted uint8 `field:"isDeleted"` // 是否已删除
} }
type DNSDomainOperator struct { type DNSDomainOperator struct {
@@ -33,6 +34,7 @@ type DNSDomainOperator struct {
Routes interface{} // 线路数据 Routes interface{} // 线路数据
IsUp interface{} // 是否在线 IsUp interface{} // 是否在线
State interface{} // 状态 State interface{} // 状态
IsDeleted interface{} // 是否已删除
} }
func NewDNSDomainOperator() *DNSDomainOperator { func NewDNSDomainOperator() *DNSDomainOperator {

View File

@@ -122,7 +122,24 @@ func (this *DNSDomainService) DeleteDNSDomain(ctx context.Context, req *pb.Delet
tx := this.NullTx() tx := this.NullTx()
err = dns.SharedDNSDomainDAO.DisableDNSDomain(tx, req.DnsDomainId) err = dns.SharedDNSDomainDAO.UpdateDomainIsDeleted(tx, req.DnsDomainId, true)
if err != nil {
return nil, err
}
return this.Success()
}
// RecoverDNSDomain 恢复删除的域名
func (this *DNSDomainService) RecoverDNSDomain(ctx context.Context, req *pb.RecoverDNSDomainRequest) (*pb.RPCSuccess, error) {
// 校验请求
_, err := this.ValidateAdmin(ctx, 0)
if err != nil {
return nil, err
}
tx := this.NullTx()
err = dns.SharedDNSDomainDAO.UpdateDomainIsDeleted(tx, req.DnsDomainId, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -242,6 +259,8 @@ func (this *DNSDomainService) FindAllEnabledBasicDNSDomainsWithDNSProviderId(ctx
Id: int64(domain.Id), Id: int64(domain.Id),
Name: domain.Name, Name: domain.Name,
IsOn: domain.IsOn == 1, IsOn: domain.IsOn == 1,
IsUp: domain.IsUp == 1,
IsDeleted: domain.IsDeleted == 1,
}) })
} }
@@ -371,6 +390,7 @@ func (this *DNSDomainService) convertDomainToPB(tx *dbs.Tx, domain *dns.DNSDomai
Name: domain.Name, Name: domain.Name,
IsOn: domain.IsOn == 1, IsOn: domain.IsOn == 1,
IsUp: domain.IsUp == 1, IsUp: domain.IsUp == 1,
IsDeleted: domain.IsDeleted == 1,
DataUpdatedAt: int64(domain.DataUpdatedAt), DataUpdatedAt: int64(domain.DataUpdatedAt),
CountNodeRecords: int64(countNodeRecords), CountNodeRecords: int64(countNodeRecords),
NodesChanged: nodesChanged, NodesChanged: nodesChanged,