Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use jsonx to add containerStyle and imageAspectRatio fields to collection config #329

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def faciaJson(playJsonVersion: PlayJsonVersion) = playJsonSpecificProject("facia
commonsIo,
playJsonVersion.lib,
"org.scala-lang.modules" %% "scala-collection-compat" % "2.11.0",
scalaLogging
scalaLogging,
playJsonExtensions
),
artifactProducingSettings(supportScala3 = playJsonVersion.supportsScala3)
)
Expand All @@ -73,7 +74,7 @@ def fapiClient(playJsonVersion: PlayJsonVersion) = playJsonSpecificProject("fap
contentApiDefault,
commercialShared,
scalaTestMockito,
mockito
mockito,
),
artifactProducingSettings(supportScala3 = false) // currently blocked by contentApi & commercialShared clients
)
Expand Down
17 changes: 12 additions & 5 deletions facia-json/src/main/scala/com/gu/facia/client/models/Config.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.gu.facia.client.models

import ai.x.play.json.Encoders.encoder
import com.typesafe.scalalogging.StrictLogging
import play.api.libs.json._
import ai.x.play.json.Jsonx

object Backfill {
implicit val jsonFormat: OFormat[Backfill] = Json.format[Backfill]
Expand Down Expand Up @@ -201,7 +203,7 @@ object DisplayHintsJson {
case class DisplayHintsJson(maxItemsToDisplay: Option[Int])

object CollectionConfigJson {
implicit val jsonFormat: OFormat[CollectionConfigJson] = Json.format[CollectionConfigJson]
implicit val jsonFormat: OFormat[CollectionConfigJson] = Jsonx.formatCaseClass[CollectionConfigJson]

val emptyConfig: CollectionConfigJson = withDefaults(None, None, None, None, None, None, None, None, None, None, None, None)

Expand All @@ -227,7 +229,9 @@ object CollectionConfigJson {
targetedTerritory: Option[TargetedTerritory] = None,
platform: Option[CollectionPlatform] = None,
frontsToolSettings: Option[FrontsToolSettings] = None,
suppressImages: Option[Boolean] = None
suppressImages: Option[Boolean] = None,
containerStyle: Option[String] = None,
imageAspectRatio: Option[String] = None
): CollectionConfigJson
= CollectionConfigJson(
displayName,
Expand All @@ -251,8 +255,9 @@ object CollectionConfigJson {
targetedTerritory,
platform,
frontsToolSettings,
suppressImages
)
suppressImages,
containerStyle,
imageAspectRatio)
}

case class CollectionConfigJson(
Expand All @@ -277,7 +282,9 @@ case class CollectionConfigJson(
targetedTerritory: Option[TargetedTerritory],
platform: Option[CollectionPlatform],
frontsToolSettings: Option[FrontsToolSettings],
suppressImages: Option[Boolean]
suppressImages: Option[Boolean],
containerStyle: Option[String],
imageAspectRatio: Option[String]
) {
val collectionType = `type`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ case class CollectionConfig(
targetedTerritory: Option[TargetedTerritory],
platform: CollectionPlatform = AnyPlatform,
frontsToolSettings: Option[FrontsToolSettings],
suppressImages: Boolean)
suppressImages: Boolean,
containerStyle: Option[String],
imageAspectRatio: Option[String])

object CollectionConfig {
val DefaultCollectionType = "fixed/small/slow-IV"
Expand All @@ -62,7 +64,9 @@ object CollectionConfig {
targetedTerritory = None,
platform = AnyPlatform,
frontsToolSettings = None,
suppressImages = false)
suppressImages = false,
containerStyle = None,
imageAspectRatio = None)

def fromCollectionJson(collectionJson: CollectionConfigJson): CollectionConfig =
CollectionConfig(
Expand All @@ -87,5 +91,7 @@ object CollectionConfig {
collectionJson.targetedTerritory,
collectionJson.platform.getOrElse(AnyPlatform),
collectionJson.frontsToolSettings,
collectionJson.suppressImages.exists(identity))
collectionJson.suppressImages.exists(identity),
collectionJson.containerStyle,
collectionJson.imageAspectRatio)
}
1 change: 1 addition & 0 deletions project/dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object Dependencies {
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.18" % Test
val scalaLogging = "com.typesafe.scala-logging" %% "scala-logging" % "3.9.5"
val commercialShared = "com.gu" %% "commercial-shared" % "6.1.8"
val playJsonExtensions = "ai.x" %% "play-json-extensions" % "0.42.0"

case class PlayJsonVersion(
majorMinorVersion: String,
Expand Down
Loading