in fapi-client/src/main/scala/com/gu/facia/api/FAPI.scala [51:67]
def frontCollections(frontId: String)
(implicit capiClient: ContentApiClient, faciaClient: ApiClient, ec: ExecutionContext): Response[List[Collection]] = {
for {
configJson <- Response.Async.Right(faciaClient.config)
frontJson <- Response.fromOption(configJson.fronts.get(frontId), NotFound(s"No front found for $frontId"))
collectionIds = frontJson.collections
collectionsJsons <- Response.Async.Right(Future.traverse(collectionIds)(faciaClient.collection))
collectionConfigJsons <- Response.traverse(
collectionIds.map(id => Response.fromOption(configJson.collections.get(id), NotFound(s"Collection config not found for $id")))
)
collectionConfigs = collectionConfigJsons.map(CollectionConfig.fromCollectionJson)
} yield {
collectionIds.lazyZip(collectionsJsons).lazyZip(collectionConfigs).toList.map { case (collectionId, collectionJson, collectionConfig) =>
Collection.fromCollectionJsonConfigAndContent(collectionId, collectionJson, collectionConfig)
}
}
}