Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions preview/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ GET /football/:competitionTag/groups/embed foo
GET /football/:competitionTag/spider/embed football.controllers.WallchartController.renderSpiderEmbed(competitionTag)

GET /football/api/match-nav/:year/:month/:day/:home/:away.json football.controllers.MoreOnMatchController.matchNavJson(year, month, day, home, away)
GET /football/api/match-header/:year/:month/:day/:home/:away.json football.controllers.MoreOnMatchController.matchHeaderJson(year, month, day, home, away)
GET /football/api/match-stats/:year/:month/:day/:home/:away.json football.controllers.MoreOnMatchController.matchStatsJson(year, month, day, home, away)
GET /football/api/match-stats-summary/:year/:month/:day/:home/:away.json football.controllers.MoreOnMatchController.matchStatsSummaryJson(year, month, day, home, away)
GET /football/api/match-nav/:year/:month/:day/:home/:away football.controllers.MoreOnMatchController.matchNav(year, month, day, home, away)
GET /football/api/match-nav/:matchId.json football.controllers.MoreOnMatchController.moreOnJson(matchId)
GET /football/api/match-nav/:matchId football.controllers.MoreOnMatchController.moreOn(matchId)
Expand Down
29 changes: 19 additions & 10 deletions sport/app/football/model/DotcomRenderingFootballDataModel.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package football.model

import common.{CanonicalLink, Edition, LinkTo}
import common.{CanonicalLink, Edition, Environment, LinkTo}
import conf.Configuration
import experiments.ActiveExperiments
import football.controllers.{CompetitionFilter, FootballPage, MatchMetadata, MatchPage}
Expand Down Expand Up @@ -52,6 +52,16 @@ trait DotcomRenderingFootballDataModel {
def pageId: String
}

sealed trait DCARUrlHelper {
def getPageUrl(path: String)(implicit request: RequestHeader): String = {
if (Environment.app == "preview") s"https://${request.host}$path" else LinkTo(path)
}

def getAjaxHost(implicit request: RequestHeader): String = {
if (Environment.app == "preview") s"https://${request.host}" else Configuration.ajax.url
}
}

object DotcomRenderingFootballDataModel {
def getConfig(page: StandalonePage)(implicit
request: RequestHeader,
Expand Down Expand Up @@ -235,7 +245,7 @@ case class DotcomRenderingFootballHeaderDataModel(
infoURL: String,
)

object DotcomRenderingFootballHeaderDataModel {
object DotcomRenderingFootballHeaderDataModel extends DCARUrlHelper {
import football.model.DotcomRenderingFootballDataModelImplicits._

def apply(theMatch: FootballMatch, competitionSummary: CompetitionSummary, related: Seq[ContentType])(implicit
Expand All @@ -245,9 +255,9 @@ object DotcomRenderingFootballHeaderDataModel {
DotcomRenderingFootballHeaderDataModel(
footballMatch = theMatch,
competitionName = competitionSummary.fullName,
liveURL = maybeMinByMin.map(x => LinkTo(x.url)),
reportURL = maybeMatchReport.map(x => LinkTo(x.url)),
infoURL = LinkTo(matchInfo.url),
liveURL = maybeMinByMin.map(x => getPageUrl(x.url)),
reportURL = maybeMatchReport.map(x => getPageUrl(x.url)),
infoURL = getPageUrl(matchInfo.url),
)
}

Expand Down Expand Up @@ -369,7 +379,7 @@ case class DotcomRenderingFootballMatchSummaryDataModel(
pageId: String,
) extends DotcomRenderingFootballDataModel

object DotcomRenderingFootballMatchSummaryDataModel {
object DotcomRenderingFootballMatchSummaryDataModel extends DCARUrlHelper {
def apply(
page: MatchPage,
matchStats: MatchStats,
Expand All @@ -389,7 +399,7 @@ object DotcomRenderingFootballMatchSummaryDataModel {
group = group,
competitionName = competitionName,
matchUrl = matchUrl(matchInfo, page),
matchHeaderUrl = matchHeaderUrl(matchInfo, page),
matchHeaderUrl = matchHeaderUrl(matchInfo),
nav = nav,
editionId = edition.id,
guardianBaseURL = Configuration.site.host,
Expand All @@ -409,11 +419,10 @@ object DotcomRenderingFootballMatchSummaryDataModel {
getMatchNavUrl(Configuration.ajax.url, localDate, homeId, awayId, page.metadata.id)
}

private def matchHeaderUrl(theMatch: FootballMatch, page: MatchPage) = {
private def matchHeaderUrl(theMatch: FootballMatch)(implicit request: RequestHeader): String = {
val (homeId, awayId) = (theMatch.homeTeam.id, theMatch.awayTeam.id)
val localDate = new JodaLocalDate(theMatch.date.getYear, theMatch.date.getMonthValue, theMatch.date.getDayOfMonth)

getMatchUrl(Configuration.ajax.url, localDate, homeId, awayId, MatchHeaderEndpoint)
getMatchUrl(getAjaxHost, localDate, homeId, awayId, MatchHeaderEndpoint)
}

import football.model.DotcomRenderingFootballDataModelImplicits._
Expand Down
Loading