Skip to content

Commit

Permalink
Add root-level fields to the Feast payload that we need in order to k…
Browse files Browse the repository at this point in the history
…now where to publish it
  • Loading branch information
fredex42 committed May 7, 2024
1 parent 38e1fd6 commit d79db1b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
15 changes: 13 additions & 2 deletions app/model/FeastAppModel.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package model

import model.editions.Edition
import play.api.libs.json._

import java.time.LocalDate

object FeastAppModel {
sealed trait ContainerItem

Expand All @@ -12,7 +15,15 @@ object FeastAppModel {
case class SubCollection(byline:Option[String], darkPalette:Option[Palette], image:Option[String], body:Option[String], title:String, lightPalette:Option[Palette], recipes:Seq[String]) extends ContainerItem

case class FeastAppContainer(id:String, title:String, body:Option[String], items:Seq[ContainerItem])
type FeastAppCuration = Map[String, IndexedSeq[FeastAppContainer]]
//type FeastAppCuration = Map[String, IndexedSeq[FeastAppContainer]]

case class FeastAppCuration(
id:String,
edition:Edition,
issueDate:LocalDate,
version:String,
fronts:Map[String,IndexedSeq[FeastAppContainer]]
)

implicit val recipeIdentifierFormat:Format[RecipeIdentifier] = Json.format[RecipeIdentifier]
implicit val recipeFormat:Format[Recipe] = Json.format[Recipe]
Expand All @@ -31,6 +42,6 @@ object FeastAppModel {
}
)
implicit val feastAppContainerFormat:Format[FeastAppContainer] = Json.format[FeastAppContainer]
//No explicit formatter required for the root level, because it's just a map
implicit val feastAppCurationFormat:Format[FeastAppCuration] = Json.format[FeastAppCuration]

}
14 changes: 10 additions & 4 deletions app/services/editions/publishing/FeastPublicationTarget.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ class FeastPublicationTarget(snsClient:AmazonSNS, config: ApplicationConfigurati
)

def transformContent(source: PublishableIssue): FeastAppCuration = {
source.fronts.map(f=>{
(transformName(f.name), f.collections.map(transformCollections).toIndexedSeq)
})
}.toMap
FeastAppCuration(
id=source.id,
issueDate=source.issueDate,
edition=source.edition,
version=source.version,
fronts=source.fronts.map(f=>{
(transformName(f.name), f.collections.map(transformCollections).toIndexedSeq)
}).toMap
)
}

override def putIssue(issue: PublishableIssue, key: Option[String]=None): Unit = {
val outputKey = key.getOrElse(EditionsBucket.createKey(issue))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class FeastPublicationTargetTest extends FreeSpec with Matchers with MockitoSuga
val toTest = new FeastPublicationTarget(mockSNS, conf, mockTSG)

val result = toTest.transformContent(incoming)
result.contains("all-recipes") shouldBe true
val allRecipesFront = result("all-recipes")
result.fronts.contains("all-recipes") shouldBe true
val allRecipesFront = result.fronts("all-recipes")
allRecipesFront.length shouldBe 1
allRecipesFront.head.title shouldBe "Dish of the day"
allRecipesFront.head.body shouldBe Some("") //this is just how the `body` field is currently rendered
Expand Down Expand Up @@ -165,7 +165,7 @@ class FeastPublicationTargetTest extends FreeSpec with Matchers with MockitoSuga
topic=None
)

val serializedVersion = """{"all-recipes":[{"id":"98e89761-fdf0-4903-b49d-2af7d66fc930","title":"Dish of the day","body":"","items":[{"recipe":{"id":"123456"}}]}]}"""
val serializedVersion = """{"id":"123456ABCD","edition":"feast-northern-hemisphere","issueDate":"2024-05-03","version":"v1","fronts":{"all-recipes":[{"id":"98e89761-fdf0-4903-b49d-2af7d66fc930","title":"Dish of the day","body":"","items":[{"recipe":{"id":"123456"}}]}]}}"""

val mockSNS = mock[AmazonSNSClient]
when(mockSNS.publish(any[PublishRequest])).thenReturn(new PublishResult())
Expand Down

0 comments on commit d79db1b

Please sign in to comment.