Skip to content

Commit

Permalink
Merge branch 'main' into give-europe-its-own-navlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
SiAdcock authored Nov 21, 2024
2 parents b2276fd + 862b548 commit ce7e0a2
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 1,047 deletions.
48 changes: 33 additions & 15 deletions applications/app/controllers/CrosswordsController.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package controllers

import com.gu.contentapi.client.model.v1.CrosswordType.{Cryptic, Quick}
import com.gu.contentapi.client.model.v1.{Crossword, ItemResponse, Content => ApiContent, Section => ApiSection}
import common.{Edition, GuLogging, ImplicitControllerExecutionContext}
import conf.Static
import contentapi.ContentApiClient
import pages.{CrosswordHtmlPage, IndexHtmlPage, PrintableCrosswordHtmlPage}
import crosswords.{
AccessibleCrosswordPage,
AccessibleCrosswordRows,
Expand All @@ -14,18 +14,20 @@ import crosswords.{
CrosswordSearchPageWithResults,
CrosswordSvg,
}
import html.HtmlPageHelpers.ContentCSSFile
import model.Cached.{RevalidatableResult, WithoutRevalidationResult}
import model._
import model.dotcomrendering.pageElements.EditionsCrosswordRenderingDataModel
import model.dotcomrendering.{DotcomRenderingDataModel, PageType}
import org.joda.time.{DateTime, LocalDate}
import pages.{CrosswordHtmlPage, IndexHtmlPage, PrintableCrosswordHtmlPage}
import play.api.data.Forms._
import play.api.data._
import play.api.mvc.{Action, RequestHeader, Result, _}
import services.{IndexPage, IndexPageItem}
import html.HtmlPageHelpers.ContentCSSFile
import model.dotcomrendering.{DotcomRenderingDataModel, PageType}
import play.api.libs.ws.WSClient
import play.api.mvc._
import renderers.DotcomRenderingService
import services.dotcomrendering.{CrosswordsPicker, RemoteRender}
import services.{IndexPage, IndexPageItem}

import scala.concurrent.Future
import scala.concurrent.duration._
Expand Down Expand Up @@ -290,17 +292,33 @@ class CrosswordSearchController(
case class CrosswordLookup(crosswordType: String, id: Int)
}

class CrosswordEditionsController(val controllerComponents: ControllerComponents)
extends BaseController
class CrosswordEditionsController(
val contentApiClient: ContentApiClient,
val controllerComponents: ControllerComponents,
val remoteRenderer: DotcomRenderingService = DotcomRenderingService(),
val wsClient: WSClient,
) extends BaseController
with GuLogging
with ImplicitControllerExecutionContext {

def digitalEdition: Action[AnyContent] =
Action.async { implicit request =>
Future.successful(
Cached(CacheTime.Default)(
RevalidatableResult.Ok("Digital Edition Crossword Entry Point"),
),
)
}
def digitalEdition: Action[AnyContent] = Action.async { implicit request =>
getCrosswords
.map(parseCrosswords)
.flatMap {
case Some(crosswordPage) =>
remoteRenderer.getEditionsCrossword(wsClient, crosswordPage)
case None => Future.successful(NotFound)
}
}

private lazy val crosswordsQuery = contentApiClient.item("crosswords")

private def getCrosswords: Future[ItemResponse] = contentApiClient.getResponse(crosswordsQuery)

private def parseCrosswords(response: ItemResponse): Option[EditionsCrosswordRenderingDataModel] =
for {
results <- response.results
quick <- results.find(_.crossword.exists(_.`type` == Quick)).flatMap(_.crossword)
cryptic <- results.find(_.crossword.exists(_.`type` == Cryptic)).flatMap(_.crossword)
} yield EditionsCrosswordRenderingDataModel(quick, cryptic)
}
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ val common = library("common")
eTagCachingS3,
nettyCodecHttp2,
contentApiClient,
contentApiModelsJson,
enumeratumPlayJson,
filters,
commonsLang,
Expand Down
10 changes: 10 additions & 0 deletions common/app/conf/switches/ABTestSwitches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ trait ABTestSwitches {
exposeClientSide = true,
highImpact = false,
)
Switch(
ABTests,
"ab-gpid-prebid-ad-units",
"Test new GPID prebid ad units",
owners = Seq(Owner.withEmail("[email protected]")),
safeState = Off,
sellByDate = Some(LocalDate.of(2024, 12, 18)),
exposeClientSide = true,
highImpact = false,
)
}
28 changes: 21 additions & 7 deletions common/app/model/CollectionConfig.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package model.pressed

import com.gu.facia.api.{models => fapi}
import com.gu.facia.client.models.{Backfill, CollectionConfigJson, Metadata, CollectionPlatform, Primary, Secondary}
import com.gu.facia.client.models.{Backfill, CollectionConfigJson, Metadata, CollectionPlatform, Secondary}

final case class CollectionConfig(
displayName: Option[String],
Expand Down Expand Up @@ -29,14 +29,28 @@ object CollectionConfig {

def make(config: fapi.CollectionConfig): CollectionConfig = {

/** Extract `primary` or `secondary` collection level tag from metadata if present. Collection level is a concept
* that allows the platforms to style containers differently based on their "level"
val betaCollections = List(
"flexible/special",
"flexible/general",
"scrollable/highlights",
"scrollable/small",
"scrollable/medium",
"scrollable/feature",
"static/medium/4",
"static/feature/2",
)

/** Collection level is a concept that allows the platforms to style containers differently based on their "level".
* Beta collections are "Secondary" if tagged as such or "Primary" otherwise. Legacy containers have no container
* level set.
*/
val collectionLevel: Option[String] = config.metadata.flatMap { metadataList =>
metadataList.collectFirst {
case Primary => "Primary"
case Secondary => "Secondary"
val collectionLevel: Option[String] = if (betaCollections.contains(config.collectionType)) {
config.metadata.getOrElse(List.empty).find(_ == Secondary) match {
case Some(_) => Some("Secondary")
case None => Some("Primary")
}
} else {
None
}

CollectionConfig(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package model.dotcomrendering.pageElements

import com.gu.contentapi.client.model.v1.Crossword
import com.gu.contentapi.json.CirceEncoders._
import io.circe.JsonObject
import io.circe.syntax._

case class EditionsCrosswordRenderingDataModel(
quick: Crossword,
cryptic: Crossword,
)

object EditionsCrosswordRenderingDataModel {
def toJson(model: EditionsCrosswordRenderingDataModel): String = {
JsonObject(
"quick" -> model.quick.asJson.dropNullValues,
"cryptic" -> model.cryptic.asJson.dropNullValues,
).asJson.dropNullValues.noSpaces
}
}
11 changes: 10 additions & 1 deletion common/app/renderers/DotcomRenderingService.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package renderers

import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem}
import com.gu.contentapi.client.model.v1.{Block, Blocks, Content}
import com.gu.contentapi.client.model.v1.{Block, Blocks, Content, Crossword}
import common.{DCRMetrics, GuLogging}
import concurrent.CircuitBreakerRegistry
import conf.Configuration
Expand All @@ -10,6 +10,7 @@ import crosswords.CrosswordPageWithContent
import http.{HttpPreconnections, ResultWithPreconnectPreload}
import model.Cached.{RevalidatableResult, WithoutRevalidationResult}
import model.dotcomrendering._
import model.dotcomrendering.pageElements.EditionsCrosswordRenderingDataModel
import model.{
CacheTime,
Cached,
Expand Down Expand Up @@ -417,6 +418,14 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload
val json = DotcomRenderingDataModel.toJson(dataModel)
post(ws, json, Configuration.rendering.articleBaseURL + "/Article", CacheTime.Facia)
}

def getEditionsCrossword(
ws: WSClient,
crosswords: EditionsCrosswordRenderingDataModel,
)(implicit request: RequestHeader): Future[Result] = {
val json = EditionsCrosswordRenderingDataModel.toJson(crosswords)
post(ws, json, Configuration.rendering.articleBaseURL + "/EditionsCrossword", CacheTime.Default)
}
}

object DotcomRenderingService {
Expand Down
2 changes: 0 additions & 2 deletions facia/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ GET /.well-known/security.txt.asc

GET /.well-known/amphtml/apikey.pub controllers.FaciaController.ampRsaPublicKey()

GET /.well-known/atproto-did controllers.Assets.at(path="/public", file="atproto-did.txt")

# AMP
GET /container/count/:count/offset/:offset/mf2.json controllers.FaciaController.renderSomeFrontContainersMf2(count: Int, offset: Int, section = "")
GET /container/count/:count/offset/:offset/section/:section/mf2.json controllers.FaciaController.renderSomeFrontContainersMf2(count: Int, offset: Int, section)
Expand Down
1 change: 0 additions & 1 deletion facia/public/atproto-did.txt

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@emotion/react": "11.11.1",
"@emotion/styled": "^10.0.27",
"@guardian/ab-core": "8.0.0",
"@guardian/commercial": "23.5.0",
"@guardian/commercial": "23.7.2",
"@guardian/core-web-vitals": "6.0.0",
"@guardian/eslint-config-typescript": "9.0.1",
"@guardian/identity-auth": "3.0.0",
Expand Down
3 changes: 2 additions & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Dependencies {
val awsVersion = "1.12.758"
val awsSdk2Version = "2.26.27"
val capiVersion = "32.0.0"
val faciaVersion = "12.1.0"
val faciaVersion = "13.0.0"
val dispatchVersion = "0.13.1"
val romeVersion = "1.0"
val jerseyVersion = "1.19.4"
Expand All @@ -32,6 +32,7 @@ object Dependencies {
val commonsIo = "commons-io" % "commons-io" % "2.16.1"
val cssParser = "net.sourceforge.cssparser" % "cssparser" % "0.9.30"
val contentApiClient = "com.gu" %% "content-api-client" % capiVersion
val contentApiModelsJson = "com.gu" %% "content-api-models-json" % "25.1.0"
val dfpAxis = "com.google.api-ads" % "dfp-axis" % "5.6.0"
val faciaFapiScalaClient = "com.gu" %% "fapi-client-play30" % faciaVersion
val identityCookie = "com.gu.identity" %% "identity-cookie" % identityLibVersion
Expand Down
Loading

0 comments on commit ce7e0a2

Please sign in to comment.