Skip to content

Commit

Permalink
Allow rendering apps version of image content (#26786)
Browse files Browse the repository at this point in the history
* Allow rendering apps version of image content

* oops: removing the old code
  • Loading branch information
alinaboghiu authored Dec 28, 2023
1 parent 04fe268 commit 7a03596
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 19 deletions.
43 changes: 26 additions & 17 deletions applications/app/controllers/ImageContentController.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package controllers

import com.gu.contentapi.client.model.{Direction, FollowingSearchQuery, SearchQuery}
import com.gu.contentapi.client.model.v1.{Block, ItemResponse, Content => ApiContent}
import com.gu.contentapi.client.model.{Direction, FollowingSearchQuery, SearchQuery}
import common._
import conf.Configuration.contentApi
import conf.switches.Switches
import contentapi.ContentApiClient
import implicits.{AppsFormat, JsonFormat}
import model._
import model.dotcomrendering.{DotcomRenderingDataModel, PageType}
import pages.ContentHtmlPage
import play.api.libs.json._
import play.api.libs.ws.WSClient
import play.api.mvc._
import services.ImageQuery
import views.support.RenderOtherStatus
import play.api.libs.json._
import conf.Configuration.contentApi
import model.dotcomrendering.{DotcomRenderingDataModel, PageType}
import renderers.DotcomRenderingService
import services.ImageQuery
import services.dotcomrendering.{ImageContentPicker, RemoteRender}
import views.support.RenderOtherStatus

import scala.concurrent.Future

Expand Down Expand Up @@ -64,17 +65,25 @@ class ImageContentController(
): Future[Result] = {
val pageType = PageType(content, request, context)

if (request.isJson) {
Future.successful(
common.renderJson(getDCRJson(content, pageType, mainBlock), content).as("application/json"),
)
} else {
remoteRenderer.getImageContent(
wsClient,
content,
pageType,
mainBlock,
)
request.getRequestFormat match {
case JsonFormat =>
Future.successful(
common.renderJson(getDCRJson(content, pageType, mainBlock), content).as("application/json"),
)
case AppsFormat =>
remoteRenderer.getAppsImageContent(
wsClient,
content,
pageType,
mainBlock,
)
case _ =>
remoteRenderer.getImageContent(
wsClient,
content,
pageType,
mainBlock,
)
}
}

Expand Down
20 changes: 18 additions & 2 deletions applications/app/services/dotcomrendering/ImageContentPicker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package services.dotcomrendering

import com.gu.contentapi.client.model.v1.{Block, ElementType}
import common.GuLogging
import implicits.AppsFormat
import model.Cors.RichRequestHeader
import model.ImageContentPage
import play.api.mvc.RequestHeader
Expand All @@ -26,9 +27,24 @@ object ImageContentPicker extends GuLogging {
}

if (tier == RemoteRender) {
DotcomponentsLogger.logger.logRequest(s"path executing in dotcomponents", Map.empty, imageContentPage.image)
if (request.getRequestFormat == AppsFormat)
DotcomponentsLogger.logger.logRequest(
s"[ArticleRendering] path executing in dotcom rendering for apps (DCAR)",
Map.empty,
imageContentPage.image,
)
else
DotcomponentsLogger.logger.logRequest(
s"[ArticleRendering] path executing in dotcomponents",
Map.empty,
imageContentPage.image,
)
} else {
DotcomponentsLogger.logger.logRequest(s"path executing in web", Map.empty, imageContentPage.image)
DotcomponentsLogger.logger.logRequest(
s"[ArticleRendering] path executing in web (frontend)",
Map.empty,
imageContentPage.image,
)
}

tier
Expand Down
11 changes: 11 additions & 0 deletions common/app/renderers/DotcomRenderingService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,17 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload
post(ws, json, Configuration.rendering.baseURL + "/Article", CacheTime.Facia)
}

def getAppsImageContent(
ws: WSClient,
imageContent: ImageContentPage,
pageType: PageType,
mainBlock: Option[Block],
)(implicit request: RequestHeader): Future[Result] = {
val dataModel = DotcomRenderingDataModel.forImageContent(imageContent, request, pageType, mainBlock)
val json = DotcomRenderingDataModel.toJson(dataModel)
post(ws, json, Configuration.rendering.baseURL + "/AppsArticle", CacheTime.Facia)
}

def getMedia(
ws: WSClient,
mediaPage: MediaPage,
Expand Down

0 comments on commit 7a03596

Please sign in to comment.