From 4ef11f7fd610cc4f81254b4f35a39db64ed20055 Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:52:04 +0000 Subject: [PATCH] Add blocks apps request format --- .../app/controllers/LiveBlogController.scala | 12 ++++++++++- .../renderers/DotcomRenderingService.scala | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/article/app/controllers/LiveBlogController.scala b/article/app/controllers/LiveBlogController.scala index e3edb4c1a142..a413bcf87a56 100644 --- a/article/app/controllers/LiveBlogController.scala +++ b/article/app/controllers/LiveBlogController.scala @@ -278,6 +278,14 @@ class LiveBlogController( } } + private def getAppsBlocksHTML(page: LiveBlogPage, blocks: Seq[Block])(implicit + request: RequestHeader, + ): Future[Html] = { + remoteRenderer.getAppsBlocks(ws, page, blocks) map { result => + new Html(result) + } + } + private[this] def renderNewerUpdatesJson( page: LiveBlogPage, lastUpdateBlockId: SinceBlockId, @@ -297,7 +305,9 @@ class LiveBlogController( for { blocksHtml <- - if (remoteRender) { + if (remoteRender && request.getRequestFormat == AppsFormat) { + getAppsBlocksHTML(page, newCapiBlocks) + } else if (remoteRender) { getDCRBlocksHTML(page, newCapiBlocks) } else { Future.successful(views.html.liveblog.liveBlogBlocks(newBlocks, page.article, Edition(request).timezone)) diff --git a/common/app/renderers/DotcomRenderingService.scala b/common/app/renderers/DotcomRenderingService.scala index 39f8c87f718e..d9cf9b59e0a1 100644 --- a/common/app/renderers/DotcomRenderingService.scala +++ b/common/app/renderers/DotcomRenderingService.scala @@ -236,6 +236,27 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload }) } + def getAppsBlocks( + ws: WSClient, + page: LiveBlogPage, + blocks: Seq[Block], + )(implicit request: RequestHeader): Future[String] = { + val dataModel = DotcomBlocksRenderingDataModel(page, request, blocks) + val json = DotcomBlocksRenderingDataModel.toJson(dataModel) + + postWithoutHandler(ws, json, Configuration.rendering.articleBaseURL + "/AppsBlocks") + .flatMap(response => { + if (response.status == 200) + Future.successful(response.body) + else + Future.failed( + DCRRenderingException( + s"getBlocks request to DCR failed: status ${response.status}, path: ${request.path}, body: ${response.body}", + ), + ) + }) + } + def getFront( ws: WSClient, page: PressedPage,