Merge pull request #24 from foomo/feature/get-content-path-data-fields

feat: add PathDataFields option on GetContent
This commit is contained in:
Jan Halfar 2021-07-01 09:53:46 +02:00 committed by GitHub
commit ae29f1060c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View File

@ -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++
}

View File

@ -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 {

View File

@ -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