@@ -5,6 +5,7 @@ import com.gu.commercial.branding.{Branding, BrandingType, Dimensions, Logo => C
55import common .{Edition , LinkTo }
66import implicits .FaciaContentFrontendHelpers .FaciaContentFrontendHelper
77import layout .{ContentCard , DiscussionSettings }
8+ import model .dotcomrendering .DotcomRenderingUtils .withoutNull
89import model .{Article , ContentFormat , ImageMedia , InlineImage , Pillar }
910import model .pressed .PressedContent
1011import 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
3841object 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