Skip to content

Commit

Permalink
Merge pull request #26991 from guardian/add-all-json-route
Browse files Browse the repository at this point in the history
Add all json route for tag pages
  • Loading branch information
abeddow91 authored Mar 25, 2024
2 parents e32d7ee + 44ffab2 commit 232eec5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions applications/app/controllers/AllIndexController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class AllIndexController(

def all(path: String): Action[AnyContent] =
Action.async { implicit request =>
val edition = Edition(request)

if (ConfigAgent.shouldServeFront(path) || defaultEdition.isEditionalised(path)) {
indexController.render(path)(request)
} else {
Expand All @@ -77,6 +75,8 @@ class AllIndexController(
}
}

def renderJson(path: String): Action[AnyContent] = indexController.render(path)

def allOn(path: String, day: String, month: String, year: String): Action[AnyContent] =
Action.async { implicit request =>
val reqDate = requestedDate(s"$year/$month/$day")
Expand Down
1 change: 1 addition & 0 deletions applications/app/services/TagPagePicker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ object TagPagePicker extends GuLogging {

def getTier(tagPage: IndexPage)(implicit request: RequestHeader): RenderType = {
lazy val participatingInTest = ActiveExperiments.isParticipating(DCRTagPages)

val checks = dcrChecks(tagPage)

val tier = decideTier(
Expand Down
2 changes: 1 addition & 1 deletion applications/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ GET /$path<.+>/latest/email.emailjson
GET /$path<.+>/latest/email.emailtxt controllers.LatestIndexController.latest(path)
GET /$path<.+>/$year<\d\d\d\d>/$month<\w\w\w>/$day<\d\d>/all controllers.AllIndexController.allOn(path, day, month, year)
GET /$path<.+>/$year<\d\d\d\d>/$month<\w\w\w>/$day<\d\d>/altdate controllers.AllIndexController.altDate(path, day, month, year)
GET /$path<.+>/all.json controllers.AllIndexController.renderJson(path)
GET /$path<.+>/all controllers.AllIndexController.all(path)


# Gallery paths
GET /$path<[\w\d-]*(/[\w\d-]*)?/gallery/.*>/lightbox.json controllers.GalleryController.lightboxJson(path)
GET /$path<[\w\d-]*(/[\w\d-]*)?/gallery/.*>.json controllers.GalleryController.renderJson(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import model.PressedCollectionFormat.pressedContentFormat

case class DotcomTagPagesRenderingDataModel(
contents: Seq[PressedContent],
pagination: Option[common.Pagination],
tags: Tags,
date: DateTime,
tzOverride: Option[DateTimeZone],
Expand All @@ -40,6 +41,7 @@ object DotcomTagPagesRenderingDataModel {
def writes(model: DotcomTagPagesRenderingDataModel) = {
Json.obj(
"contents" -> model.contents,
"pagination" -> model.pagination,
"date" -> model.date.toString(),
"tzOverride" -> model.tzOverride.map(_.toString),
"previousAndNext" -> model.previousAndNext.map(previousAndNext =>
Expand Down Expand Up @@ -97,8 +99,14 @@ object DotcomTagPagesRenderingDataModel {
}
.getOrElse(Map.empty[String, EditionCommercialProperties])

// `/all` tag pages have pagination in the metadata whilst for all other tag pages, pagination is in the tags.
val pagination = page.metadata.pagination.orElse {
page.tags.tags.headOption.flatMap(_.pagination)
}

DotcomTagPagesRenderingDataModel(
contents = page.contents.map(_.faciaItem),
pagination = pagination,
tags = page.tags,
date = page.date,
tzOverride = page.tzOverride,
Expand Down
1 change: 1 addition & 0 deletions dev-build/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ GET /$path<.+>/latest/email.emailjson
GET /$path<.+>/latest/email.emailtxt controllers.LatestIndexController.latest(path)
GET /$path<.+>/$year<\d\d\d\d>/$month<\w\w\w>/$day<\d\d>/all controllers.AllIndexController.allOn(path, day, month, year)
GET /$path<.+>/$year<\d\d\d\d>/$month<\w\w\w>/$day<\d\d>/altdate controllers.AllIndexController.altDate(path, day, month, year)
GET /$path<.+>/all.json controllers.AllIndexController.renderJson(path)
GET /$path<.+>/all controllers.AllIndexController.all(path)

# Newspaper pages paths
Expand Down

0 comments on commit 232eec5

Please sign in to comment.