/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.2.6 * User agent: apibuilder app.apibuilder.io/bombas/storeback-api/0.2.6/http4s_0_17 */ package bombas.storeback.api.v0.server import org.http4s.dsl._ import bombas.storeback.api.v0.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 == "0" => true case _ => false } } } trait ProductRoutes { 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 GetResponse object GetResponse { case class HTTP200(value: bombas.storeback.api.v0.models.Product, headers: Seq[org.http4s.Header] = Nil) extends GetResponse case class HTTP400(headers: Seq[org.http4s.Header] = Nil) extends GetResponse case class HTTP404(headers: Seq[org.http4s.Header] = Nil) extends GetResponse case class UndocumentedResponse(response: fs2.Task[org.http4s.Response]) extends GetResponse } def get( _req: org.http4s.Request, productId: String ): fs2.Task[GetResponse] def apiVersionMatch(req: org.http4s.Message): Boolean = ApiVersion(req) def service() = org.http4s.HttpService { case _req @ GET -> Root / "v1" / "products" / productId if apiVersionMatch(_req) => get(_req, productId).flatMap { case GetResponse.HTTP200(value, headers) => Ok(value).putHeaders(headers: _*) case GetResponse.HTTP400(headers) => BadRequest().putHeaders(headers: _*) case GetResponse.HTTP404(headers) => NotFound().putHeaders(headers: _*) case GetResponse.UndocumentedResponse(response) => response } case _req @ GET -> Root / "v1" / "products" / productId if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") } }