Skip to content

Commit

Permalink
Fix delete video handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianp26 committed May 5, 2017
1 parent 94a2b5c commit 900e603
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {
})
port := app.String(cli.StringOpt{
Name: "port",
Value: "8084",
Value: "8080",
Desc: "Port to listen on",
EnvVar: "APP_PORT",
})
Expand Down
32 changes: 18 additions & 14 deletions mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ func (m *relatedContentMapper) mapRelatedContent() ([]byte, string, error) {
return nil, "", err
}

var relatedItems []Item
collectionContainerUUID := NewNameUUIDFromBytes([]byte(videoUUID)).String()

var cc ContentCollection
if !m.isDeleteEvent() {
relatedItemsArray, err := getObjectsArrayField(relatedField, m.unmarshalled, videoUUID, m)
if err != nil {
return nil, videoUUID, err
}

relatedItems = m.retrieveRelatedItems(relatedItemsArray, videoUUID)
relatedItems := m.retrieveRelatedItems(relatedItemsArray, videoUUID)
cc = m.newContentCollection(collectionContainerUUID, relatedItems)
}

mc := m.buildMappedContent(videoUUID, relatedItems)
mc := m.newMappedContent(collectionContainerUUID, cc)

marshalledPubEvent, err := json.Marshal(mc)
if err != nil {
Expand All @@ -62,22 +65,23 @@ func (m *relatedContentMapper) retrieveRelatedItems(relatedItemsArray []map[stri
return result
}

func (m *relatedContentMapper) buildMappedContent(videoUUID string, items []Item) MappedContent {
collectionContainerUUID := NewNameUUIDFromBytes([]byte(videoUUID)).String()
cc := ContentCollection{
UUID: collectionContainerUUID,
func (m *relatedContentMapper) newMappedContent(ccUUID string, cc ContentCollection) MappedContent {
return MappedContent{
Payload: cc,
ContentURI: contentURIPrefix + ccUUID,
LastModified: m.lastModified,
UUID: ccUUID,
}
}

func (m *relatedContentMapper) newContentCollection(ccUUID string, items []Item) ContentCollection {
return ContentCollection{
UUID: ccUUID,
Items: items,
PublishReference: m.tid,
LastModified: m.lastModified,
CollectionType: collectionType,
}

return MappedContent{
Payload: cc,
ContentURI: contentURIPrefix + collectionContainerUUID,
LastModified: m.lastModified,
UUID: collectionContainerUUID,
}
}

func getRequiredStringField(key string, obj map[string]interface{}) (string, error) {
Expand Down

0 comments on commit 900e603

Please sign in to comment.