/** * Generated by API Builder - https://www.apibuilder.io * Service version: 1.1.0 * User agent: apibuilder app.apibuilder.io/paintbatch-com/paint-batch-optimizer/1.1.0/http4s_0_17 */ package com.paintbatch.server import org.http4s.dsl._ import com.paintbatch.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 } } } trait HealthcheckRoutes { 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 GetHealthcheckResponse object GetHealthcheckResponse { case class HTTP200(value: com.paintbatch.models.Healthcheck, headers: Seq[org.http4s.Header] = Nil) extends GetHealthcheckResponse case class UndocumentedResponse(response: fs2.Task[org.http4s.Response]) extends GetHealthcheckResponse } def getHealthcheck( _req: org.http4s.Request ): fs2.Task[GetHealthcheckResponse] def apiVersionMatch(req: org.http4s.Message): Boolean = ApiVersion(req) def service() = org.http4s.HttpService { case _req @ GET -> Root / "_internal_" / "healthcheck" if apiVersionMatch(_req) => getHealthcheck(_req).flatMap { case GetHealthcheckResponse.HTTP200(value, headers) => Ok(value).putHeaders(headers: _*) case GetHealthcheckResponse.UndocumentedResponse(response) => response } case _req @ GET -> Root / "_internal_" / "healthcheck" if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") } } trait OptimizeRequestRoutes { 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 PostOptimizeResponse object PostOptimizeResponse { case class HTTP200(value: String, headers: Seq[org.http4s.Header] = Nil) extends PostOptimizeResponse case class HTTP422(value: com.paintbatch.models.ReadableError, headers: Seq[org.http4s.Header] = Nil) extends PostOptimizeResponse case class UndocumentedResponse(response: fs2.Task[org.http4s.Response]) extends PostOptimizeResponse } def postOptimize( _req: org.http4s.Request, body: => org.http4s.DecodeResult[com.paintbatch.models.OptimizeRequest] ): fs2.Task[PostOptimizeResponse] def apiVersionMatch(req: org.http4s.Message): Boolean = ApiVersion(req) def service() = org.http4s.HttpService { case _req @ POST -> Root / "v2" / "optimize" if apiVersionMatch(_req) => postOptimize(_req, _req.attemptAs[com.paintbatch.models.OptimizeRequest]).flatMap { case PostOptimizeResponse.HTTP200(value, headers) => Ok(value).putHeaders(headers: _*) case PostOptimizeResponse.HTTP422(value, headers) => UnprocessableEntity(value).putHeaders(headers: _*) case PostOptimizeResponse.UndocumentedResponse(response) => response } case _req @ POST -> Root / "v2" / "optimize" if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") } }