Import ZoneMeta in domain history
This commit is contained in:
parent
0625d8f5ec
commit
ab6fe350ca
|
@ -100,7 +100,7 @@ func zoneHandler(f func(*config.Options, *happydns.Domain, *happydns.Zone, httpr
|
|||
// Check that the zoneid exists in the domain history
|
||||
found := false
|
||||
for _, v := range domain.ZoneHistory {
|
||||
if v.Id == zoneid {
|
||||
if v == zoneid {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
|
@ -185,6 +185,6 @@ func deleteZone(opts *config.Options, ps httprouter.Params, body io.Reader) api.
|
|||
if err != nil {
|
||||
return api.NewAPIErrorResponse(http.StatusNotFound, err)
|
||||
} else {
|
||||
return api.NewAPIResponse(true, storage.MainStore.DeleteZone(&happydns.Zone{Id: zoneid}))
|
||||
return api.NewAPIResponse(true, storage.MainStore.DeleteZone(&happydns.Zone{ZoneMeta: happydns.ZoneMeta{Id: zoneid}}))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,9 +149,37 @@ func domainHandler(f func(*config.Options, *happydns.Domain, io.Reader) Response
|
|||
}
|
||||
}
|
||||
|
||||
type apiDomain struct {
|
||||
Id int64 `json:"id"`
|
||||
IdUser int64 `json:"id_owner"`
|
||||
IdSource int64 `json:"id_source"`
|
||||
DomainName string `json:"domain"`
|
||||
ZoneHistory []happydns.ZoneMeta `json:"zone_history"`
|
||||
}
|
||||
|
||||
func getDomain(_ *config.Options, domain *happydns.Domain, body io.Reader) Response {
|
||||
ret := &apiDomain{
|
||||
Id: domain.Id,
|
||||
IdUser: domain.IdUser,
|
||||
IdSource: domain.IdSource,
|
||||
DomainName: domain.DomainName,
|
||||
ZoneHistory: []happydns.ZoneMeta{},
|
||||
}
|
||||
|
||||
for _, zm := range domain.ZoneHistory {
|
||||
zoneMeta, err := storage.MainStore.GetZoneMeta(zm)
|
||||
|
||||
if err != nil {
|
||||
return APIErrorResponse{
|
||||
err: err,
|
||||
}
|
||||
}
|
||||
|
||||
ret.ZoneHistory = append(ret.ZoneHistory, *zoneMeta)
|
||||
}
|
||||
|
||||
return APIResponse{
|
||||
response: domain,
|
||||
response: ret,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
22
api/zones.go
22
api/zones.go
|
@ -41,6 +41,7 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
|
||||
|
@ -74,7 +75,7 @@ func zoneHandler(f func(*config.Options, *happydns.Domain, *happydns.Zone, httpr
|
|||
// Check that the zoneid exists in the domain history
|
||||
found := false
|
||||
for _, v := range domain.ZoneHistory {
|
||||
if v.Id == zoneid {
|
||||
if v == zoneid {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
|
@ -195,9 +196,12 @@ func importZone(opts *config.Options, domain *happydns.Domain, body io.Reader) R
|
|||
}
|
||||
|
||||
myZone := &happydns.Zone{
|
||||
IdAuthor: domain.IdUser,
|
||||
DefaultTTL: defaultTTL,
|
||||
Services: services,
|
||||
ZoneMeta: happydns.ZoneMeta{
|
||||
IdAuthor: domain.IdUser,
|
||||
DefaultTTL: defaultTTL,
|
||||
LastModified: time.Now(),
|
||||
},
|
||||
Services: services,
|
||||
}
|
||||
|
||||
err = storage.MainStore.CreateZone(myZone)
|
||||
|
@ -208,9 +212,7 @@ func importZone(opts *config.Options, domain *happydns.Domain, body io.Reader) R
|
|||
}
|
||||
|
||||
domain.ZoneHistory = append(
|
||||
[]happydns.ZoneMeta{
|
||||
happydns.ZoneMeta{myZone.Id},
|
||||
}, domain.ZoneHistory...)
|
||||
[]int64{myZone.Id}, domain.ZoneHistory...)
|
||||
|
||||
err = storage.MainStore.UpdateDomain(domain)
|
||||
if err != nil {
|
||||
|
@ -220,7 +222,7 @@ func importZone(opts *config.Options, domain *happydns.Domain, body io.Reader) R
|
|||
}
|
||||
|
||||
return APIResponse{
|
||||
response: happydns.ZoneMeta{myZone.Id},
|
||||
response: &myZone.ZoneMeta,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,6 +242,8 @@ func updateZoneService(opts *config.Options, domain *happydns.Domain, zone *happ
|
|||
}
|
||||
}
|
||||
|
||||
zone.LastModified = time.Now()
|
||||
|
||||
err = storage.MainStore.UpdateZone(zone)
|
||||
if err != nil {
|
||||
return APIErrorResponse{
|
||||
|
@ -267,6 +271,8 @@ func deleteZoneService(opts *config.Options, domain *happydns.Domain, zone *happ
|
|||
}
|
||||
}
|
||||
|
||||
zone.LastModified = time.Now()
|
||||
|
||||
err = storage.MainStore.UpdateZone(zone)
|
||||
if err != nil {
|
||||
return APIErrorResponse{
|
||||
|
|
|
@ -36,11 +36,11 @@ import (
|
|||
)
|
||||
|
||||
type Domain struct {
|
||||
Id int64 `json:"id"`
|
||||
IdUser int64 `json:"id_owner"`
|
||||
IdSource int64 `json:"id_source"`
|
||||
DomainName string `json:"domain"`
|
||||
ZoneHistory []ZoneMeta `json:"zone_history"`
|
||||
Id int64 `json:"id"`
|
||||
IdUser int64 `json:"id_owner"`
|
||||
IdSource int64 `json:"id_source"`
|
||||
DomainName string `json:"domain"`
|
||||
ZoneHistory []int64 `json:"zone_history"`
|
||||
}
|
||||
|
||||
type Domains []*Domain
|
||||
|
|
|
@ -38,18 +38,18 @@ import (
|
|||
)
|
||||
|
||||
type ZoneMeta struct {
|
||||
Id int64 `json:"id"`
|
||||
Id int64 `json:"id"`
|
||||
IdAuthor int64 `json:"id_author"`
|
||||
DefaultTTL uint32 `json:"default_ttl"`
|
||||
LastModified time.Time `json:"last_modified,omitempty"`
|
||||
CommitMsg *string `json:"commit_message,omitempty"`
|
||||
CommitDate *time.Time `json:"commit_date,omitempty"`
|
||||
Published *time.Time `json:"published,omitempty"`
|
||||
}
|
||||
|
||||
type Zone struct {
|
||||
Id int64 `json:"id"`
|
||||
IdAuthor int64 `json:"id_author"`
|
||||
DefaultTTL uint32 `json:"default_ttl"`
|
||||
LastModified *time.Time `json:"last_modified,omitempty"`
|
||||
CommitMsg *string `json:"commit_message,omitempty"`
|
||||
CommitDate *time.Time `json:"commit_date,omitempty"`
|
||||
Published *time.Time `json:"published,omitempty"`
|
||||
Services map[string][]*ServiceCombined `json:"services"`
|
||||
ZoneMeta
|
||||
Services map[string][]*ServiceCombined `json:"services"`
|
||||
}
|
||||
|
||||
func (z *Zone) FindService(id []byte) (string, *ServiceCombined) {
|
||||
|
|
|
@ -75,6 +75,7 @@ type Storage interface {
|
|||
ClearUsers() error
|
||||
|
||||
GetZone(id int64) (*happydns.Zone, error)
|
||||
GetZoneMeta(id int64) (*happydns.ZoneMeta, error)
|
||||
CreateZone(zone *happydns.Zone) error
|
||||
UpdateZone(zone *happydns.Zone) error
|
||||
DeleteZone(zone *happydns.Zone) error
|
||||
|
|
Loading…
Reference in New Issue