Skip to content

Commit

Permalink
BDOG-3276: refactors search by path to use route model
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrpix committed Oct 24, 2024
1 parent ba38b3d commit c6d5776
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 283 deletions.
4 changes: 2 additions & 2 deletions app/uk/gov/hmrc/cataloguefrontend/CatalogueController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import play.twirl.api.Html
import uk.gov.hmrc.cataloguefrontend.auth.{AuthController, CatalogueAuthBuilders}
import uk.gov.hmrc.cataloguefrontend.connector.BuildDeployApiConnector.PrototypeStatus
import uk.gov.hmrc.cataloguefrontend.connector.*
import uk.gov.hmrc.cataloguefrontend.connector.RouteRulesConnector.{Route, RouteType}
import uk.gov.hmrc.cataloguefrontend.connector.RouteConfigurationConnector.{Route, RouteType}
import uk.gov.hmrc.cataloguefrontend.connector.model.RepositoryModules
import uk.gov.hmrc.cataloguefrontend.cost.{CostEstimateConfig, CostEstimationService, Zone}
import uk.gov.hmrc.cataloguefrontend.leakdetection.LeakDetectionService
Expand Down Expand Up @@ -86,7 +86,7 @@ class CatalogueController @Inject() (
serviceMetricsConnector : ServiceMetricsConnector,
serviceConfigsConnector : ServiceConfigsConnector,
releasesConnector : ReleasesConnector,
routesRulesConnector : RouteRulesConnector,
routesRulesConnector : RouteConfigurationConnector,
override val auth : FrontendAuthComponents
)(using
override val ec: ExecutionContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SearchByUrlController @Inject() (
.fold(
formWithErrors => Future.successful(Ok(searchByUrlPage(formWithErrors, Nil))),
query => searchByUrlService
.search(query.name)
.searchProdFrontendPath(query.name)
.map: results =>
Ok(searchByUrlPage(UrlSearchFilter.form.bindFromRequest(), results))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal

@Singleton
class RouteRulesConnector @Inject() (
class RouteConfigurationConnector @Inject()(
httpClientV2 : HttpClientV2,
servicesConfig: ServicesConfig
)(using ExecutionContext):
import HttpReads.Implicits._
import RouteRulesConnector._
import RouteConfigurationConnector._

private val logger = Logger(getClass)

Expand All @@ -46,7 +46,7 @@ class RouteRulesConnector @Inject() (
service : Option[ServiceName] = None
, routeType : Option[RouteType] = None
, environment: Option[Environment] = None
)(using
)(using
HeaderCarrier
): Future[Seq[Route]] =

Expand All @@ -57,7 +57,7 @@ class RouteRulesConnector @Inject() (
"environment" -> environment.map(_.asString)
).collect:
case (paramName, Some(paramValue)) => paramName -> paramValue

val url = url"$baseUrl/service-configs/routes?$queryParams"

httpClientV2
Expand All @@ -67,8 +67,23 @@ class RouteRulesConnector @Inject() (
case NonFatal(ex) =>
logger.error(s"An error occurred when connecting to $url: ${ex.getMessage}", ex)
Seq.empty

def searchFrontendPath(
term : String
, environment: Option[Environment]
)(using
HeaderCarrier
): Future[Seq[Route]] =
val url = url"$baseUrl/service-configs/frontend-routes/search?frontendPath=$term&environment=${environment.map(_.asString)}"
httpClientV2
.get(url)
.execute[Seq[Route]]
.recover:
case NonFatal(ex) =>
logger.error(s"An error occurred when connecting to $url: ${ex.getMessage}", ex)
Seq.empty

object RouteRulesConnector:
object RouteConfigurationConnector:
import uk.gov.hmrc.cataloguefrontend.util.{FromString, FromStringEnum, Parser}
import FromStringEnum._

Expand Down Expand Up @@ -102,4 +117,4 @@ object RouteRulesConnector:
~ (__ \ "routeType" ).read[RouteType]
~ (__ \ "environment" ).read[Environment]
)(Route.apply)
end RouteRulesConnector
end RouteConfigurationConnector

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package uk.gov.hmrc.cataloguefrontend.service

import javax.inject.Singleton
import uk.gov.hmrc.cataloguefrontend.model.Environment
import uk.gov.hmrc.cataloguefrontend.connector.RouteRulesConnector.{Route, RouteType}
import uk.gov.hmrc.cataloguefrontend.connector.RouteConfigurationConnector.{Route, RouteType}

@Singleton
class RouteRulesService:
Expand Down
37 changes: 8 additions & 29 deletions app/uk/gov/hmrc/cataloguefrontend/service/SearchByUrlService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,25 @@

package uk.gov.hmrc.cataloguefrontend.service

import java.net.{URI, URISyntaxException}
import uk.gov.hmrc.cataloguefrontend.connector.RouteConfigurationConnector.Route

import javax.inject._
import uk.gov.hmrc.cataloguefrontend.connector.SearchByUrlConnector
import uk.gov.hmrc.cataloguefrontend.model.{Environment, ServiceName}
import java.net.{URI, URISyntaxException}
import javax.inject.*
import uk.gov.hmrc.cataloguefrontend.connector.RouteConfigurationConnector
import uk.gov.hmrc.cataloguefrontend.model.Environment
import uk.gov.hmrc.http.HeaderCarrier

import scala.concurrent.{ExecutionContext, Future}

@Singleton
class SearchByUrlService @Inject() (
searchByUrlConnector: SearchByUrlConnector
routeConfigurationConnector: RouteConfigurationConnector
)(using ec: ExecutionContext):

import SearchByUrlService._

def search(
term : Option[String],
environment: Environment = Environment.Production
)(using HeaderCarrier): Future[Seq[FrontendRoutes]] =
def searchProdFrontendPath(term: Option[String])(using HeaderCarrier): Future[Seq[Route]] =
if isValidSearchTerm(term)
then
searchByUrlConnector.search(takeUrlPath(term.get)).map: searchResults =>
searchResults
.filter(_.environment == environment)
.map(r => r.copy(routes = r.routes.filterNot(_.isDevhub)))
routeConfigurationConnector.searchFrontendPath(takeUrlPath(term.get), Some(Environment.Production))
else
Future.successful(Nil)

Expand Down Expand Up @@ -77,17 +70,3 @@ class SearchByUrlService @Inject() (
url.getPath.trim

end SearchByUrlService

object SearchByUrlService:
case class FrontendRoute(
frontendPath : String,
ruleConfigurationUrl: String = "",
isRegex : Boolean = false,
isDevhub : Boolean = false,
)

case class FrontendRoutes(
service : ServiceName,
environment: Environment,
routes : Seq[FrontendRoute]
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import play.api.Logger
import play.api.data.{Form, Forms}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.cataloguefrontend.auth.CatalogueAuthBuilders
import uk.gov.hmrc.cataloguefrontend.connector.RouteRulesConnector
import uk.gov.hmrc.cataloguefrontend.connector.RouteRulesConnector.RouteType
import uk.gov.hmrc.cataloguefrontend.connector.RouteConfigurationConnector
import uk.gov.hmrc.cataloguefrontend.connector.RouteConfigurationConnector.RouteType
import uk.gov.hmrc.cataloguefrontend.model.{Environment, ServiceName}
import uk.gov.hmrc.cataloguefrontend.shuttering.ShutterConnector.ShutterEventsFilter
import uk.gov.hmrc.cataloguefrontend.shuttering.view.html.ShutterEventsPage
Expand All @@ -34,10 +34,10 @@ import scala.util.control.NonFatal

@Singleton
class ShutterEventsController @Inject() (
override val mcc : MessagesControllerComponents,
connector : ShutterConnector,
routeRulesConnector :RouteRulesConnector,
override val auth: FrontendAuthComponents
override val mcc : MessagesControllerComponents,
connector : ShutterConnector,
routeRulesConnector: RouteConfigurationConnector,
override val auth : FrontendAuthComponents
)(using
override val ec: ExecutionContext
) extends FrontendController(mcc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import cats.data.OptionT
import cats.implicits.*

import javax.inject.{Inject, Singleton}
import uk.gov.hmrc.cataloguefrontend.connector.{GitHubProxyConnector, RouteRulesConnector}
import uk.gov.hmrc.cataloguefrontend.connector.RouteRulesConnector.RouteType
import uk.gov.hmrc.cataloguefrontend.connector.{GitHubProxyConnector, RouteConfigurationConnector}
import uk.gov.hmrc.cataloguefrontend.connector.RouteConfigurationConnector.RouteType
import uk.gov.hmrc.cataloguefrontend.model.{Environment, ServiceName}
import uk.gov.hmrc.internalauth.client.AuthenticatedRequest
import uk.gov.hmrc.http.HeaderCarrier
Expand All @@ -33,7 +33,7 @@ import org.jsoup.nodes.Document
class ShutterService @Inject() (
shutterConnector : ShutterConnector,
shutterGroupsConnector: ShutterGroupsConnector,
routeRulesConnector : RouteRulesConnector,
routeRulesConnector : RouteConfigurationConnector,
githubConnector : GitHubProxyConnector
)(using
ExecutionContext
Expand Down
31 changes: 15 additions & 16 deletions app/uk/gov/hmrc/cataloguefrontend/view/SearchByUrlPage.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*@

@import uk.gov.hmrc.cataloguefrontend.{routes => appRoutes}
@import uk.gov.hmrc.cataloguefrontend.service.SearchByUrlService.FrontendRoutes
@import uk.gov.hmrc.cataloguefrontend.connector.RouteConfigurationConnector.Route

@this()


@(form : Form[?],
searchResults : Seq[FrontendRoutes]
searchResults : Seq[Route]
)(implicit
request : RequestHeader
)
Expand Down Expand Up @@ -82,20 +83,18 @@ <h1 id="search-service-header" class="page-heading mt-4">Search for a service by
</thead>
<tbody class="list">
@for(result <- searchResults) {
@for(route <- result.routes) {
<tr>
<td>
<a id="link-to-@{result.service.asString}" href="@appRoutes.CatalogueController.service(result.service)">@result.service.asString</a>
</td>
<td>
@if(route.isRegex) {
@route.frontendPath
} else {
<a href="https://[email protected]" target="_blank" rel="noreferrer noopener">@route.frontendPath <span class="glyphicon glyphicon-new-window"/></a>
}
</td>
</tr>
}
<tr>
<td>
<a id="link-to-@{result.serviceName.asString}" href="@appRoutes.CatalogueController.service(result.serviceName)">@{result.serviceName.asString}</a>
</td>
<td>
@if(result.isRegex) {
@result.path
} else {
<a href="https://[email protected]" target="_blank" rel="noreferrer noopener">@result.path <span class="glyphicon glyphicon-new-window"/></a>
}
</td>
</tr>
}
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@import uk.gov.hmrc.cataloguefrontend.connector.{GitRepository, JenkinsJob}
@import uk.gov.hmrc.cataloguefrontend.prcommenter.PrCommenterReport
@import uk.gov.hmrc.cataloguefrontend.cost.{CostEstimateConfig, ServiceCostEstimate}
@import uk.gov.hmrc.cataloguefrontend.connector.RouteRulesConnector.{Route, RouteType}
@import uk.gov.hmrc.cataloguefrontend.connector.RouteConfigurationConnector.{Route, RouteType}
@import uk.gov.hmrc.cataloguefrontend.servicecommissioningstatus.Lifecycle
@import uk.gov.hmrc.cataloguefrontend.serviceconfigs.ServiceConfigsService
@import uk.gov.hmrc.cataloguefrontend.view.ViewMessages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*@

@import uk.gov.hmrc.cataloguefrontend.connector.RouteRulesConnector.Route
@import uk.gov.hmrc.cataloguefrontend.connector.RouteConfigurationConnector.Route

@(inconsistentRoutes: Seq[Route])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*@

@import uk.gov.hmrc.cataloguefrontend.connector.RouteRulesConnector.{Route, RouteType}
@import uk.gov.hmrc.cataloguefrontend.connector.RouteConfigurationConnector.{Route, RouteType}

@(routes: Seq[Route])
<div id="service-urls-section" class="card">
Expand Down
Loading

0 comments on commit c6d5776

Please sign in to comment.