Skip to content

Commit

Permalink
Asset Map Includes for multi-locale queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian Vidmar committed May 12, 2020
1 parent 8d62fd2 commit a29b575
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
14 changes: 14 additions & 0 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,17 @@ func (col *Collection) ToIncludesAssetMap() map[string]*IncludeAsset {
}
return includesAssetMap
}

// ToIncludesLocalizedAssetMap returns a map of Asset's from the Includes
func (col *Collection) ToIncludesLocalizedAssetMap() map[string]*IncludeLocalizedAsset {
var includesAsset []*IncludeLocalizedAsset
includesAssetMap := make(map[string]*IncludeLocalizedAsset)

byteArray, _ := json.Marshal(col.Includes["Asset"])
json.NewDecoder(bytes.NewReader(byteArray)).Decode(&includesAsset)

for _, a := range includesAsset {
includesAssetMap[a.Sys.ID] = a
}
return includesAssetMap
}
19 changes: 13 additions & 6 deletions include.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package contentful

/* // Include model
type Include struct {
Entry []*Entry
Asset []*Asset
} */

//IncludeEntry model
type IncludeEntry struct {
Fields map[string]interface{} `json:"fields,omitempty"`
Expand All @@ -24,3 +18,16 @@ type IncludeAsset struct {
Fields *IncludeFileFields `json:"fields"`
Sys *Sys `json:"sys"`
}

// IncludeFileLocalizedFields model
type IncludeFileLocalizedFields struct {
Title map[string]string `json:"title,omitempty"`
Description map[string]string `json:"description,omitempty"`
File map[string]*File `json:"file,omitempty"`
}

// IncludeLocalizedAsset model
type IncludeLocalizedAsset struct {
Fields *IncludeFileLocalizedFields `json:"fields"`
Sys *Sys `json:"sys"`
}

0 comments on commit a29b575

Please sign in to comment.