Skip to content

Commit

Permalink
Add gallery count to PressedCard
Browse files Browse the repository at this point in the history
  • Loading branch information
abeddow91 committed Dec 12, 2024
1 parent adaa612 commit 88eb8a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions common/app/model/PressedCard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.gu.facia.api.utils.FaciaContentUtils.fold
import com.gu.facia.api.{models => fapi, utils => fapiutils}
import model.CardStylePicker
import org.joda.time.DateTime
import com.gu.contentapi.client.model.v1.{Content, ElementType}

final case class PressedCard(
id: String,
Expand All @@ -20,6 +21,7 @@ final case class PressedCard(
shortUrl: String,
group: String,
isLive: Boolean,
galleryCount: Option[Int],
) {
def withoutTrailText: PressedCard = copy(trailText = None)
}
Expand All @@ -36,6 +38,18 @@ object PressedCard {
).map(_.toJodaDateTime)
}

def extractGalleryCount(fc: FaciaContent): Option[Int] = {
def countImagesInGallery(content: Content): Option[Int] =
content.elements.map(_.count(el => el.`type` == ElementType.Image && el.relation == "gallery")).filter(_ > 0)

fold(fc)(
curatedContent => countImagesInGallery(curatedContent.content),
supportingCuratedContent => countImagesInGallery(supportingCuratedContent.content),
_ => None,
latestSnap => latestSnap.latestContent.flatMap(countImagesInGallery),
)
}

PressedCard(
id = FaciaContentUtils.id(content),
cardStyle = CardStyle.make(CardStylePicker(content)),
Expand All @@ -48,6 +62,7 @@ object PressedCard {
group = FaciaContentUtils.group(content),
trailText = FaciaContentUtils.trailText(content),
starRating = FaciaContentUtils.starRating(content),
galleryCount = extractGalleryCount(content),
)
}
}
1 change: 1 addition & 0 deletions common/test/common/TrailsToShowcaseTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,7 @@ class TrailsToShowcaseTest extends AnyFlatSpec with Matchers with EitherValues {
shortUrlPath = None,
isLive = true,
group = "",
galleryCount = None,
)

val discussionSettings = PressedDiscussionSettings(
Expand Down
1 change: 1 addition & 0 deletions common/test/common/facia/FixtureBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ object FixtureBuilder {
shortUrl = "",
group = "0",
isLive = false,
galleryCount = None,
)

def mkDiscussion(): PressedDiscussionSettings =
Expand Down

0 comments on commit 88eb8a0

Please sign in to comment.