in football/src/main/scala/com/gu/mobile/notifications/football/lib/ArticleSearcher.scala [14:43]
def tryToMatchWithCapiArticle(matchesData: List[RawMatchData])(implicit ec: ExecutionContext): Future[List[MatchDataWithArticle]] = {
Batch.process(matchesData, 5) { matchData =>
val homeTeam = matchData.matchDay.homeTeam.id
val awayTeam = matchData.matchDay.awayTeam.id
val matchDate = matchData.matchDay.date
val fromInstant: Instant = ZonedDateTime.of(matchDate.getYear,
matchDate.getMonthValue,
matchDate.getDayOfMonth,
matchDate.getHour,
matchDate.getMinute,
matchDate.getSecond,
matchDate.getSecond * 1000,
ZoneOffset.UTC
).toInstant
val response = capiClient.getResponse(
new SearchQuery()
.fromDate(fromInstant)
.reference(s"pa-football-team/$homeTeam,pa-football-team/$awayTeam")
.tag("tone/minutebyminute"))
val articleId = response.map(_.results.headOption.map(_.id))
articleId.foreach {
case Some(id) => logger.info(s"Attaching article $id to matchId ${matchData.matchDay.id}")
case None => logger.info(s"No article found for matchId ${matchData.matchDay.id}")
}
articleId.map(matchData.withArticle)
}
}