Skip to content

Commit 97d8b59

Browse files
authored
Merge pull request #28197 from guardian/enrich-trail-type
add trail text and gallery count to trail type
2 parents 52f3744 + 10f735d commit 97d8b59

File tree

2 files changed

+38
-39
lines changed

2 files changed

+38
-39
lines changed

common/app/agents/DeeplyReadAgent.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package agents
22

3-
import com.gu.contentapi.client.model.v1.Content
3+
import com.gu.contentapi.client.model.v1.{Content, ElementType}
44
import com.gu.contentapi.client.utils.CapiModelEnrichment.RenderingFormat
55
import common._
66
import contentapi.ContentApiClient
@@ -123,6 +123,9 @@ class DeeplyReadAgent(contentApiClient: ContentApiClient, ophanApi: OphanApi) ex
123123
avatarUrl = None,
124124
branding = None,
125125
discussion = DiscussionSettings.fromTrail(FaciaContentConvert.contentToFaciaContent(content)),
126+
trailText = content.fields.flatMap(_.trailText),
127+
galleryCount =
128+
content.elements.map(_.count(el => el.`type` == ElementType.Image && el.relation == "gallery")).filter(_ > 0),
126129
)
127130
}
128131

common/app/model/dotcomrendering/Trail.scala

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.gu.commercial.branding.{Branding, BrandingType, Dimensions, Logo => C
55
import common.{Edition, LinkTo}
66
import implicits.FaciaContentFrontendHelpers.FaciaContentFrontendHelper
77
import layout.{ContentCard, DiscussionSettings}
8+
import model.dotcomrendering.DotcomRenderingUtils.withoutNull
89
import model.{Article, ContentFormat, ImageMedia, InlineImage, Pillar}
910
import model.pressed.PressedContent
1011
import play.api.libs.json.{Json, OWrites, Writes}
@@ -33,6 +34,8 @@ case class Trail(
3334
avatarUrl: Option[String],
3435
branding: Option[Branding],
3536
discussion: DiscussionSettings,
37+
trailText: Option[String],
38+
galleryCount: Option[Int],
3639
)
3740

3841
object Trail {
@@ -53,7 +56,35 @@ object Trail {
5356

5457
implicit val discussionWrites: OWrites[DiscussionSettings] = Json.writes[DiscussionSettings]
5558

56-
implicit val OnwardItemWrites: OWrites[Trail] = Json.writes[Trail]
59+
implicit val OnwardItemWrites: Writes[Trail] = Writes { trail =>
60+
val jsObject = Json.obj(
61+
"url" -> trail.url,
62+
"linkText" -> trail.linkText,
63+
"showByline" -> trail.showByline,
64+
"byline" -> trail.byline,
65+
"masterImage" -> trail.masterImage,
66+
"image" -> trail.image,
67+
"carouselImages" -> trail.carouselImages,
68+
"ageWarning" -> trail.ageWarning,
69+
"isLiveBlog" -> trail.isLiveBlog,
70+
"pillar" -> trail.pillar,
71+
"designType" -> trail.designType,
72+
"format" -> trail.format,
73+
"webPublicationDate" -> trail.webPublicationDate,
74+
"headline" -> trail.headline,
75+
"mediaType" -> trail.mediaType,
76+
"shortUrl" -> trail.shortUrl,
77+
"kickerText" -> trail.kickerText,
78+
"starRating" -> trail.starRating,
79+
"avatarUrl" -> trail.avatarUrl,
80+
"branding" -> trail.branding,
81+
"discussion" -> trail.discussion,
82+
"trailText" -> trail.trailText,
83+
"galleryCount" -> trail.galleryCount,
84+
)
85+
86+
withoutNull(jsObject)
87+
}
5788

5889
private def contentCardToAvatarUrl(contentCard: ContentCard): Option[String] = {
5990

@@ -99,43 +130,6 @@ object Trail {
99130
url <- masterImage.url
100131
} yield url
101132

102-
def contentCardToTrail(contentCard: ContentCard): Option[Trail] = {
103-
for {
104-
properties <- contentCard.properties
105-
maybeContent <- properties.maybeContent
106-
metadata = maybeContent.metadata
107-
pillar <- metadata.pillar
108-
url <- properties.webUrl
109-
headline = contentCard.header.headline
110-
isLiveBlog = properties.isLiveBlog
111-
showByline = properties.showByline
112-
webPublicationDate <- contentCard.webPublicationDate.map(x => x.toDateTime().toString())
113-
shortUrl <- contentCard.shortUrl
114-
} yield Trail(
115-
url = url,
116-
linkText = "",
117-
showByline = showByline,
118-
byline = contentCard.byline.map(x => x.get),
119-
masterImage = getMasterUrl(maybeContent.trail.trailPicture),
120-
image = maybeContent.trail.thumbnailPath,
121-
carouselImages = getImageSources(maybeContent.trail.trailPicture),
122-
ageWarning = None,
123-
isLiveBlog = isLiveBlog,
124-
pillar = TrailUtils.normalisePillar(Some(pillar)),
125-
designType = metadata.designType.toString,
126-
format = metadata.format.getOrElse(ContentFormat.defaultContentFormat),
127-
webPublicationDate = webPublicationDate,
128-
headline = headline,
129-
mediaType = contentCard.mediaType.map(x => x.toString),
130-
shortUrl = shortUrl,
131-
kickerText = contentCard.header.kicker.flatMap(_.properties.kickerText),
132-
starRating = contentCard.starRating,
133-
avatarUrl = contentCardToAvatarUrl(contentCard),
134-
branding = contentCard.branding,
135-
discussion = contentCard.discussionSettings,
136-
)
137-
}
138-
139133
def pressedContentToTrail(content: PressedContent)(implicit
140134
request: RequestHeader,
141135
): Trail = {
@@ -168,6 +162,8 @@ object Trail {
168162
avatarUrl = None,
169163
branding = content.branding(Edition(request)),
170164
discussion = DiscussionSettings.fromTrail(content),
165+
trailText = content.card.trailText,
166+
galleryCount = content.card.galleryCount,
171167
)
172168
}
173169
}

0 commit comments

Comments
 (0)