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
|
// Check that the zoneid exists in the domain history
|
||||||
found := false
|
found := false
|
||||||
for _, v := range domain.ZoneHistory {
|
for _, v := range domain.ZoneHistory {
|
||||||
if v.Id == zoneid {
|
if v == zoneid {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -185,6 +185,6 @@ func deleteZone(opts *config.Options, ps httprouter.Params, body io.Reader) api.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.NewAPIErrorResponse(http.StatusNotFound, err)
|
return api.NewAPIErrorResponse(http.StatusNotFound, err)
|
||||||
} else {
|
} 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 {
|
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{
|
return APIResponse{
|
||||||
response: domain,
|
response: ret,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
api/zones.go
16
api/zones.go
|
@ -41,6 +41,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
"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
|
// Check that the zoneid exists in the domain history
|
||||||
found := false
|
found := false
|
||||||
for _, v := range domain.ZoneHistory {
|
for _, v := range domain.ZoneHistory {
|
||||||
if v.Id == zoneid {
|
if v == zoneid {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -195,8 +196,11 @@ func importZone(opts *config.Options, domain *happydns.Domain, body io.Reader) R
|
||||||
}
|
}
|
||||||
|
|
||||||
myZone := &happydns.Zone{
|
myZone := &happydns.Zone{
|
||||||
|
ZoneMeta: happydns.ZoneMeta{
|
||||||
IdAuthor: domain.IdUser,
|
IdAuthor: domain.IdUser,
|
||||||
DefaultTTL: defaultTTL,
|
DefaultTTL: defaultTTL,
|
||||||
|
LastModified: time.Now(),
|
||||||
|
},
|
||||||
Services: services,
|
Services: services,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,9 +212,7 @@ func importZone(opts *config.Options, domain *happydns.Domain, body io.Reader) R
|
||||||
}
|
}
|
||||||
|
|
||||||
domain.ZoneHistory = append(
|
domain.ZoneHistory = append(
|
||||||
[]happydns.ZoneMeta{
|
[]int64{myZone.Id}, domain.ZoneHistory...)
|
||||||
happydns.ZoneMeta{myZone.Id},
|
|
||||||
}, domain.ZoneHistory...)
|
|
||||||
|
|
||||||
err = storage.MainStore.UpdateDomain(domain)
|
err = storage.MainStore.UpdateDomain(domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -220,7 +222,7 @@ func importZone(opts *config.Options, domain *happydns.Domain, body io.Reader) R
|
||||||
}
|
}
|
||||||
|
|
||||||
return APIResponse{
|
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)
|
err = storage.MainStore.UpdateZone(zone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return APIErrorResponse{
|
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)
|
err = storage.MainStore.UpdateZone(zone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return APIErrorResponse{
|
return APIErrorResponse{
|
||||||
|
|
|
@ -40,7 +40,7 @@ type Domain struct {
|
||||||
IdUser int64 `json:"id_owner"`
|
IdUser int64 `json:"id_owner"`
|
||||||
IdSource int64 `json:"id_source"`
|
IdSource int64 `json:"id_source"`
|
||||||
DomainName string `json:"domain"`
|
DomainName string `json:"domain"`
|
||||||
ZoneHistory []ZoneMeta `json:"zone_history"`
|
ZoneHistory []int64 `json:"zone_history"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Domains []*Domain
|
type Domains []*Domain
|
||||||
|
|
|
@ -39,16 +39,16 @@ import (
|
||||||
|
|
||||||
type ZoneMeta struct {
|
type ZoneMeta struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
}
|
|
||||||
|
|
||||||
type Zone struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
IdAuthor int64 `json:"id_author"`
|
IdAuthor int64 `json:"id_author"`
|
||||||
DefaultTTL uint32 `json:"default_ttl"`
|
DefaultTTL uint32 `json:"default_ttl"`
|
||||||
LastModified *time.Time `json:"last_modified,omitempty"`
|
LastModified time.Time `json:"last_modified,omitempty"`
|
||||||
CommitMsg *string `json:"commit_message,omitempty"`
|
CommitMsg *string `json:"commit_message,omitempty"`
|
||||||
CommitDate *time.Time `json:"commit_date,omitempty"`
|
CommitDate *time.Time `json:"commit_date,omitempty"`
|
||||||
Published *time.Time `json:"published,omitempty"`
|
Published *time.Time `json:"published,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Zone struct {
|
||||||
|
ZoneMeta
|
||||||
Services map[string][]*ServiceCombined `json:"services"`
|
Services map[string][]*ServiceCombined `json:"services"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,7 @@ type Storage interface {
|
||||||
ClearUsers() error
|
ClearUsers() error
|
||||||
|
|
||||||
GetZone(id int64) (*happydns.Zone, error)
|
GetZone(id int64) (*happydns.Zone, error)
|
||||||
|
GetZoneMeta(id int64) (*happydns.ZoneMeta, error)
|
||||||
CreateZone(zone *happydns.Zone) error
|
CreateZone(zone *happydns.Zone) error
|
||||||
UpdateZone(zone *happydns.Zone) error
|
UpdateZone(zone *happydns.Zone) error
|
||||||
DeleteZone(zone *happydns.Zone) error
|
DeleteZone(zone *happydns.Zone) error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user