Skip to content

Commit

Permalink
Add EditionIdCAPIMapper
Browse files Browse the repository at this point in the history
We noticed that the `MostPopularAgent` queries CAPI using the wrong edition id for the Europe and International editions. It uses "EUR" and "INT" instead of "EUROPE" and "INTERNATIONAL" as expected by CAPI. We're introducing this mapper that will populate the agent with content for these two editions.

Co-authored-by: Ravi <[email protected]>
  • Loading branch information
ioannakok and arelra committed Feb 7, 2024
1 parent c7fec18 commit 31ddec2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 2 additions & 3 deletions common/app/common/Edition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ abstract class Edition(
val homePagePath: String = s"/$networkFrontId"

def isEditionalised(sectionId: String): Boolean = editionalisedSections.contains(sectionId)
def matchesCookie(cookieValue: String): Boolean = id.equalsIgnoreCase(cookieValue)
def timezoneId = ZoneId.of(timezone.getID)
}

Expand Down Expand Up @@ -82,8 +81,8 @@ object Edition {
}

def apply(request: RequestHeader): Edition = {
val cookieValue = editionFromRequest(request)
allEditions.find(_.matchesCookie(cookieValue)).getOrElse(defaultEdition)
val edition = editionFromRequest(request)
allEditions.find(_.id.equalsIgnoreCase(edition)).getOrElse(defaultEdition)
}

def others(implicit request: RequestHeader): Seq[Edition] = {
Expand Down
14 changes: 13 additions & 1 deletion common/app/contentapi/ContentApiClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ trait ApiQueryDefaults extends GuLogging {

def item(id: String): ItemQuery = CapiContentApiClient.item(id)

def item(id: String, edition: Edition): ItemQuery = item(id, edition.id)
def item(id: String, edition: Edition): ItemQuery = item(id, EditionIdCAPIMapper.mapEditionId(edition))

//Strip unnecessary leading slash in path, as this affects signing of IAM requests
def item(id: String, edition: String): ItemQuery =
Expand Down Expand Up @@ -194,3 +194,15 @@ class PreviewContentApi(httpClient: HttpClient)(implicit executionContext: Execu
apiKey = contentApi.key.getOrElse(""),
)
}

object EditionIdCAPIMapper {
def mapEditionId(edition: Edition): String = {
edition match {
case editions.Uk => "UK"
case editions.Us => "US"
case editions.Au => "AU"
case editions.International => "INTERNATIONAL"
case editions.Europe => "EUROPE"
}
}
}
Binary file not shown.

0 comments on commit 31ddec2

Please sign in to comment.