Skip to content

Commit

Permalink
Merge pull request #27566 from guardian/blocks-apps-request
Browse files Browse the repository at this point in the history
Add blocks apps request format
  • Loading branch information
DanielCliftonGuardian authored Oct 29, 2024
2 parents 37d8c28 + 4ef11f7 commit a75e590
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
12 changes: 11 additions & 1 deletion article/app/controllers/LiveBlogController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))
Expand Down
21 changes: 21 additions & 0 deletions common/app/renderers/DotcomRenderingService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a75e590

Please sign in to comment.