/** * Generated by API Builder - https://www.apibuilder.io * Service version: 1.1.0 * User agent: apibuilder app.apibuilder.io/hbc/api-product-recommendations-lat/1.1.0/http4s_0_15 */ package com.hbc.api.product.recommendations.lat.v1.server import org.http4s.dsl._ import com.hbc.api.product.recommendations.lat.v1.models.json._ private[server] object Matchers { implicit lazy val queryParamDecodeBigDecimal: org.http4s.QueryParamDecoder[BigDecimal] = org.http4s.QueryParamDecoder.fromUnsafeCast[BigDecimal](p => BigDecimal(p.value))("BigDecimal") implicit lazy val queryParamDecodeInstant: org.http4s.QueryParamDecoder[_root_.java.time.Instant] = org.http4s.QueryParamDecoder.fromUnsafeCast[_root_.java.time.Instant](p => _root_.java.time.OffsetDateTime.parse(p.value).toInstant)("_root_.java.time.Instant") implicit lazy val queryParamDecodeLocalDate: org.http4s.QueryParamDecoder[_root_.java.time.LocalDate] = org.http4s.QueryParamDecoder.fromUnsafeCast[_root_.java.time.LocalDate](p => _root_.java.time.LocalDate.parse(p.value))("_root_.java.time.LocalDate") implicit lazy val queryParamDecodeUUID: org.http4s.QueryParamDecoder[_root_.java.util.UUID] = org.http4s.QueryParamDecoder.fromUnsafeCast[_root_.java.util.UUID](p => _root_.java.util.UUID.fromString(p.value))("_root_.java.util.UUID") object ApiVersion { val ApiVersionMajor = { "X-Apidoc-Version-Major".ci } def apply(req: org.http4s.Message): Boolean = req.headers.get(ApiVersionMajor) match { case Some(v) if v.value == "1" => true case _ => false } } object SimilarProductContextVal { def unapply(s: String): Option[com.hbc.api.product.recommendations.lat.v1.models.SimilarProductContext] = com.hbc.api.product.recommendations.lat.v1.models.SimilarProductContext.fromString(s) } object AbTestNameOptStringMatcher extends OptionalQueryParamDecoderMatcher[String]("abTestName") object AbTestVariantOptStringMatcher extends OptionalQueryParamDecoderMatcher[String]("abTestVariant") object ColorOptStringMatcher extends OptionalQueryParamDecoderMatcher[String]("color") object LimitIntDef10Matcher extends QueryParamDecoderMatcher[Int]("limit") { override def unapply(params: Map[String, Seq[String]]) = super.unapply(params).orElse(Some(10)) } } trait SimilarProductRecommendationRoutes { import Matchers._ implicit def circeJsonDecoder[A](implicit decoder: _root_.io.circe.Decoder[A]) = org.http4s.circe.jsonOf[A] implicit def circeJsonEncoder[A](implicit encoder: _root_.io.circe.Encoder[A]) = org.http4s.circe.jsonEncoderOf[A] sealed trait GetByContextAndProductIdResponse object GetByContextAndProductIdResponse { case class HTTP200(value: com.hbc.api.product.recommendations.lat.v1.models.SimilarProductRecommendation, headers: Seq[org.http4s.Header] = Nil) extends GetByContextAndProductIdResponse case class UndocumentedResponse(response: scalaz.concurrent.Task[org.http4s.Response]) extends GetByContextAndProductIdResponse } def getByContextAndProductId( _req: org.http4s.Request, context: com.hbc.api.product.recommendations.lat.v1.models.SimilarProductContext, productId: String, color: _root_.scala.Option[String], limit: Int, abTestName: _root_.scala.Option[String], abTestVariant: _root_.scala.Option[String] ): scalaz.concurrent.Task[GetByContextAndProductIdResponse] def apiVersionMatch(req: org.http4s.Message): Boolean = ApiVersion(req) def service() = org.http4s.HttpService { case _req @ GET -> Root / "similarProductRecommendations" / SimilarProductContextVal(context) / productId :? ColorOptStringMatcher(color) +& LimitIntDef10Matcher(limit) +& AbTestNameOptStringMatcher(abTestName) +& AbTestVariantOptStringMatcher(abTestVariant) if apiVersionMatch(_req) => getByContextAndProductId(_req, context, productId, color, limit, abTestName, abTestVariant).flatMap { case GetByContextAndProductIdResponse.HTTP200(value, headers) => Ok(value).putHeaders(headers: _*) case GetByContextAndProductIdResponse.UndocumentedResponse(response) => response } case _req @ GET -> Root / "similarProductRecommendations" / SimilarProductContextVal(context) / productId :? ColorOptStringMatcher(color) +& LimitIntDef10Matcher(limit) +& AbTestNameOptStringMatcher(abTestName) +& AbTestVariantOptStringMatcher(abTestVariant) if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") } }