mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	增加删除/恢复DNS域名API
This commit is contained in:
		@@ -214,7 +214,7 @@ func (this *DNSDomainDAO) FindDomainRouteName(tx *dbs.Tx, domainId int64, routeC
 | 
			
		||||
// ExistAvailableDomains 判断是否有域名可选
 | 
			
		||||
func (this *DNSDomainDAO) ExistAvailableDomains(tx *dbs.Tx) (bool, error) {
 | 
			
		||||
	subQuery, err := SharedDNSProviderDAO.Query(tx).
 | 
			
		||||
		Where("state=1").                   // 这里要使用非变量
 | 
			
		||||
		Where("state=1"). // 这里要使用非变量
 | 
			
		||||
		ResultPk().
 | 
			
		||||
		AsSQL()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -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) {
 | 
			
		||||
	one, err := this.Query(tx).
 | 
			
		||||
		State(DNSDomainStateEnabled).
 | 
			
		||||
		Attr("isOn", true).
 | 
			
		||||
		Attr("providerId", providerId).
 | 
			
		||||
		Attr("name", domainName).
 | 
			
		||||
		Find()
 | 
			
		||||
@@ -280,3 +279,11 @@ func (this *DNSDomainDAO) UpdateDomainIsUp(tx *dbs.Tx, domainId int64, isUp bool
 | 
			
		||||
		Set("isUp", isUp).
 | 
			
		||||
		UpdateQuickly()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateDomainIsDeleted 设置域名为删除
 | 
			
		||||
func (this *DNSDomainDAO) UpdateDomainIsDeleted(tx *dbs.Tx, domainId int64, isDeleted bool) error {
 | 
			
		||||
	return this.Query(tx).
 | 
			
		||||
		Pk(domainId).
 | 
			
		||||
		Set("isDeleted", isDeleted).
 | 
			
		||||
		UpdateQuickly()
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@ type DNSDomain struct {
 | 
			
		||||
	Routes        string `field:"routes"`        // 线路数据
 | 
			
		||||
	IsUp          uint8  `field:"isUp"`          // 是否在线
 | 
			
		||||
	State         uint8  `field:"state"`         // 状态
 | 
			
		||||
	IsDeleted     uint8  `field:"isDeleted"`     // 是否已删除
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type DNSDomainOperator struct {
 | 
			
		||||
@@ -33,6 +34,7 @@ type DNSDomainOperator struct {
 | 
			
		||||
	Routes        interface{} // 线路数据
 | 
			
		||||
	IsUp          interface{} // 是否在线
 | 
			
		||||
	State         interface{} // 状态
 | 
			
		||||
	IsDeleted     interface{} // 是否已删除
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewDNSDomainOperator() *DNSDomainOperator {
 | 
			
		||||
 
 | 
			
		||||
@@ -122,7 +122,24 @@ func (this *DNSDomainService) DeleteDNSDomain(ctx context.Context, req *pb.Delet
 | 
			
		||||
 | 
			
		||||
	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 {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
@@ -239,9 +256,11 @@ func (this *DNSDomainService) FindAllEnabledBasicDNSDomainsWithDNSProviderId(ctx
 | 
			
		||||
	result := []*pb.DNSDomain{}
 | 
			
		||||
	for _, domain := range domains {
 | 
			
		||||
		result = append(result, &pb.DNSDomain{
 | 
			
		||||
			Id:   int64(domain.Id),
 | 
			
		||||
			Name: domain.Name,
 | 
			
		||||
			IsOn: domain.IsOn == 1,
 | 
			
		||||
			Id:        int64(domain.Id),
 | 
			
		||||
			Name:      domain.Name,
 | 
			
		||||
			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,
 | 
			
		||||
		IsOn:               domain.IsOn == 1,
 | 
			
		||||
		IsUp:               domain.IsUp == 1,
 | 
			
		||||
		IsDeleted:          domain.IsDeleted == 1,
 | 
			
		||||
		DataUpdatedAt:      int64(domain.DataUpdatedAt),
 | 
			
		||||
		CountNodeRecords:   int64(countNodeRecords),
 | 
			
		||||
		NodesChanged:       nodesChanged,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user