From 5788fd203d457532a0df25665eb58fdda50a60f4 Mon Sep 17 00:00:00 2001 From: franklin Date: Wed, 30 Jun 2021 15:53:16 +0200 Subject: [PATCH] feat: add PathDataFields option on GetContent --- content/reponode.go | 9 +++++++-- repo/repo.go | 5 +++-- requests/requests.go | 9 +++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/content/reponode.go b/content/reponode.go index 466feb4..e7a3bd9 100644 --- a/content/reponode.go +++ b/content/reponode.go @@ -51,7 +51,7 @@ func (node *RepoNode) InPath(path []*Item) bool { } // GetPath get a path for a repo node -func (node *RepoNode) GetPath() []*Item { +func (node *RepoNode) GetPath(dataFields []string) []*Item { var ( parentNode = node.parent @@ -67,8 +67,13 @@ func (node *RepoNode) GetPath() []*Item { i = 0 path = make([]*Item, pathLength) ) + + if dataFields == nil { + dataFields = []string{} + } + for parentNode != nil { - path[i] = parentNode.ToItem([]string{}) + path[i] = parentNode.ToItem(dataFields) parentNode = parentNode.parent i++ } diff --git a/repo/repo.go b/repo/repo.go index 37d5ecd..6fc5357 100644 --- a/repo/repo.go +++ b/repo/repo.go @@ -13,11 +13,12 @@ import ( "github.com/foomo/contentserver/status" + "go.uber.org/zap" + "github.com/foomo/contentserver/content" "github.com/foomo/contentserver/logger" "github.com/foomo/contentserver/requests" "github.com/foomo/contentserver/responses" - "go.uber.org/zap" ) const maxGetURIForNodeRecursionLevel = 1000 @@ -199,7 +200,7 @@ func (repo *Repo) GetContent(r *requests.Content) (c *content.SiteContent, err e c.Dimension = resolvedDimension c.URI = resolvedURI c.Item = node.ToItem(r.DataFields) - c.Path = node.GetPath() + c.Path = node.GetPath(r.PathDataFields) // fetch URIs for all dimensions uris := make(map[string]string) for dimensionName := range repo.Directory { diff --git a/requests/requests.go b/requests/requests.go index 83109ae..132cc93 100644 --- a/requests/requests.go +++ b/requests/requests.go @@ -36,10 +36,11 @@ type Nodes struct { // Content - the standard request to contentserver type Content struct { - Env *Env `json:"env"` - URI string `json:"URI"` - Nodes map[string]*Node `json:"nodes"` - DataFields []string `json:"dataFields"` + Env *Env `json:"env"` + URI string `json:"URI"` + Nodes map[string]*Node `json:"nodes"` + DataFields []string `json:"dataFields"` + PathDataFields []string `json:"pathDataFields"` } // Update - request an update