From a41f80c7e6af174181506cadb49e1a9ca95a3077 Mon Sep 17 00:00:00 2001 From: Marko Milic Date: Fri, 10 Jun 2016 16:17:28 +0200 Subject: [PATCH] This closes #3 - Filter by tags --- src/main/scala/code/snippet/ApiExplorer.scala | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/scala/code/snippet/ApiExplorer.scala b/src/main/scala/code/snippet/ApiExplorer.scala index 8691a01a..f553361e 100644 --- a/src/main/scala/code/snippet/ApiExplorer.scala +++ b/src/main/scala/code/snippet/ApiExplorer.scala @@ -100,6 +100,14 @@ class ApiExplorer extends Loggable { logger.info(s"showOBWG is $showOBWGParam") + val tagsParam: Option[List[String]] = for { + x <- S.param("tags") + y <- Some(x.split(",").toList) + } yield { + y + } + logger.info(s"tags are $tagsParam") + // This parameter stops the default catalog kicking in val ignoreDefaultCatalog: Option[Boolean] = for { @@ -286,8 +294,19 @@ class ApiExplorer extends Loggable { case _ => filteredResources2 } - val resources = filteredResources3 + val tags = tagsParam match { + case Some(x) => x + case _ => List() + } + val filteredResources4 : List[ResourceDoc] = for { + x <- filteredResources3 + y <- tags + if x.tags.contains(y.trim) + } yield { + x + } + val resources = if (filteredResources4.length > 0) filteredResources4 else filteredResources3 // Headline and Description of the search val (catalogHeadline, catalogDescription) = List(showCore, showOBWG, showPSD2) match { @@ -429,7 +448,7 @@ class ApiExplorer extends Loggable { // Create a list of (version, url) used to populate the versions whilst preserving the other parameters - val versionUrls = supportedApiVersions.map(i => (i, s"${CurrentReq.value.uri}?version=${i}&list-all-banks=${listAllBanks}${catalogParams}")) + val versionUrls: List[(String, String)] = supportedApiVersions.map(i => (i, s"${CurrentReq.value.uri}?version=${i}&list-all-banks=${listAllBanks}${catalogParams}")) // So we can highlight (or maybe later exclusively show) the "active" banks in a sandbox.