Skip to content

Commit

Permalink
Merge pull request #27424 from guardian/gl/pass-boostlevel-to-dcr
Browse files Browse the repository at this point in the history
Add boostlevel to frontend
  • Loading branch information
Georges-GNM authored Sep 5, 2024
2 parents b2f263d + 4662ae9 commit 33f95ec
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 10 deletions.
4 changes: 3 additions & 1 deletion common/app/layout/DisplaySettings.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package layout

import com.gu.facia.api.utils.BoostLevel
import model.pressed._

case class DisplaySettings(
/** TODO check if this should actually be used to determine anything at an item level; if not, remove it */
isBoosted: Boolean,
boostLevel: Option[BoostLevel],
showBoostedHeadline: Boolean,
showQuotedHeadline: Boolean,
imageHide: Boolean,
Expand All @@ -15,6 +16,7 @@ object DisplaySettings {
def fromTrail(faciaContent: PressedContent): DisplaySettings =
DisplaySettings(
faciaContent.display.isBoosted,
faciaContent.display.boostLevel,
faciaContent.display.showBoostedHeadline,
faciaContent.display.showQuotedHeadline,
faciaContent.display.imageHide,
Expand Down
23 changes: 23 additions & 0 deletions common/app/model/Formats.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model

import com.gu.contentapi.client.utils.DesignType
import com.gu.facia.api.utils.BoostLevel
import common.Pagination
import json.ObjectDeduplication.deduplicate
import model.content._
Expand Down Expand Up @@ -49,6 +50,27 @@ object TimelinesThriftAtomFormat extends Format[com.gu.contentatom.thrift.atom.t
def writes(timeline: com.gu.contentatom.thrift.atom.timeline.TimelineAtom): JsObject = JsObject(Seq.empty)
}

object BoostLevelFormat extends Format[BoostLevel] {
def reads(json: JsValue): JsResult[BoostLevel] = {
json match {
case JsString("default") => JsSuccess(BoostLevel.Default)
case JsString("boost") => JsSuccess(BoostLevel.Boost)
case JsString("megaboost") => JsSuccess(BoostLevel.MegaBoost)
case JsString("gigaboost") => JsSuccess(BoostLevel.GigaBoost)
case _ => JsError("Could not convert BoostLevel")
}
}

def writes(boostLevel: BoostLevel): JsValue = {
boostLevel match {
case BoostLevel.Default => JsString("default")
case BoostLevel.Boost => JsString("boost")
case BoostLevel.MegaBoost => JsString("megaboost")
case BoostLevel.GigaBoost => JsString("gigaboost")
}
}
}

object CardStyleFormat extends Format[CardStyle] {
def reads(json: JsValue): JsResult[CardStyle] = {
(json \ "type").transform[JsString](Reads.JsStringReads) match {
Expand Down Expand Up @@ -240,6 +262,7 @@ object PressedContentFormat {
implicit val itemKickerFormat: ItemKickerFormat.format.type = ItemKickerFormat.format
implicit val tagKickerFormat: OFormat[TagKicker] = ItemKickerFormat.tagKickerFormat
implicit val pressedCardHeader: OFormat[PressedCardHeader] = Json.format[PressedCardHeader]
implicit val boostLevel: BoostLevelFormat.type = BoostLevelFormat
implicit val pressedDisplaySettings: OFormat[PressedDisplaySettings] = Json.format[PressedDisplaySettings]
implicit val pressedDiscussionSettings: OFormat[PressedDiscussionSettings] = Json.format[PressedDiscussionSettings]
implicit val pressedCard: OFormat[PressedCard] = Json.format[PressedCard]
Expand Down
4 changes: 3 additions & 1 deletion common/app/model/PressedDisplaySettings.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package model.pressed

import com.gu.facia.api.utils.FaciaContentUtils
import com.gu.facia.api.utils.{BoostLevel, FaciaContentUtils}
import com.gu.facia.api.{models => fapi}

final case class PressedDisplaySettings(
isBoosted: Boolean,
boostLevel: Option[BoostLevel],
showBoostedHeadline: Boolean,
showQuotedHeadline: Boolean,
imageHide: Boolean,
Expand All @@ -17,6 +18,7 @@ object PressedDisplaySettings {
PressedDisplaySettings(
imageHide = contentProperties.imageHide,
isBoosted = FaciaContentUtils.isBoosted(content),
boostLevel = Some(FaciaContentUtils.boostLevel(content)),
showBoostedHeadline = FaciaContentUtils.showBoostedHeadline(content),
showQuotedHeadline = FaciaContentUtils.showQuotedHeadline(content),
showLivePlayable = FaciaContentUtils.showLivePlayable(content),
Expand Down
15 changes: 8 additions & 7 deletions common/test/common/TrailsToShowcaseTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package common

import com.gu.contentapi.client.model.v1.{Content => ApiContent}
import com.gu.contentapi.client.utils.CapiModelEnrichment.RichOffsetDateTime
import com.gu.facia.api.utils.Editorial
import com.gu.facia.api.utils.{BoostLevel, Editorial}
import com.sun.syndication.feed.module.mediarss.MediaEntryModule
import com.sun.syndication.feed.synd.SyndPerson
import implicits.Dates.jodaToJavaInstant
Expand Down Expand Up @@ -336,10 +336,10 @@ class TrailsToShowcaseTest extends AnyFlatSpec with Matchers with EitherValues {
// Strip them to provide the least friction to editors
val bulletItemsWithHtml =
"""
|-<p>Bullet 1</p>
|- <strong>Bullet 2</strong>
|-<b>Unclosed
|""".stripMargin
|-<p>Bullet 1</p>
|- <strong>Bullet 2</strong>
|-<b>Unclosed
|""".stripMargin

val curatedContent = makePressedContent(
webPublicationDate = wayBackWhen,
Expand Down Expand Up @@ -584,8 +584,8 @@ class TrailsToShowcaseTest extends AnyFlatSpec with Matchers with EitherValues {
// Showcase specifies 2 or 3 items
val bulletEncodedTrailText =
"""
| - 1 bullet item is not going to be enough
|""".stripMargin
| - 1 bullet item is not going to be enough
|""".stripMargin

val bulletedContent = makePressedContent(
webPublicationDate = wayBackWhen,
Expand Down Expand Up @@ -1404,6 +1404,7 @@ class TrailsToShowcaseTest extends AnyFlatSpec with Matchers with EitherValues {

val displaySettings = PressedDisplaySettings(
isBoosted = false,
boostLevel = Some(BoostLevel.Default),
showBoostedHeadline = false,
showQuotedHeadline = false,
showLivePlayable = false,
Expand Down
2 changes: 2 additions & 0 deletions common/test/common/facia/FixtureBuilder.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package common.facia

import com.gu.facia.api.utils.BoostLevel
import model.facia.PressedCollection
import model.{FrontProperties, PressedPage, SeoData}
import model.pressed._
Expand Down Expand Up @@ -110,6 +111,7 @@ object FixtureBuilder {
def mkDisplay(): PressedDisplaySettings =
PressedDisplaySettings(
isBoosted = false,
boostLevel = Some(BoostLevel.Default),
showBoostedHeadline = false,
showQuotedHeadline = false,
imageHide = false,
Expand Down
2 changes: 2 additions & 0 deletions common/test/views/support/TrackingCodeBuilderTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package views.support

import com.gu.commercial.branding._
import com.gu.facia.api.utils.BoostLevel
import common.commercial._
import layout.cards.Half
import layout.{
Expand Down Expand Up @@ -151,6 +152,7 @@ class TrackingCodeBuilderTest extends AnyFlatSpec with Matchers with BeforeAndAf
mediaType = None,
displaySettings = DisplaySettings(
isBoosted = false,
boostLevel = Some(BoostLevel.Default),
showBoostedHeadline = false,
showQuotedHeadline = false,
imageHide = false,
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Dependencies {
val awsVersion = "1.12.758"
val awsSdk2Version = "2.26.27"
val capiVersion = "31.1.0"
val faciaVersion = "8.0.1"
val faciaVersion = "9.0.0"
val dispatchVersion = "0.13.1"
val romeVersion = "1.0"
val jerseyVersion = "1.19.4"
Expand Down

0 comments on commit 33f95ec

Please sign in to comment.