mirror of
https://github.com/foomo/contentful.git
synced 2026-08-16 13:40:18 +00:00
Asset Map Includes for multi-locale queries
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
+13
-6
@@ -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"`
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user