Skip to content

Commit

Permalink
Merge pull request #24 from foomo/feature/get-content-path-data-fields
Browse files Browse the repository at this point in the history
feat: add PathDataFields option on GetContent
  • Loading branch information
janhalfar authored Jul 1, 2021
2 parents c9bf566 + 5788fd2 commit ae29f10
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 7 additions & 2 deletions content/reponode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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++
}
Expand Down
5 changes: 3 additions & 2 deletions repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions requests/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae29f10

Please sign in to comment.