/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1 * User agent: apibuilder app.apibuilder.io/faberoh/order-api/0.0.1/http4s_0_18 */ package com.faberoh.order.api.v0.server import org.http4s.circe.decodeUri import org.http4s.circe.encodeUri import org.http4s.dsl.{io => _, _} import cats.effect._ import cats.implicits._ import scala.language.higherKinds import com.faberoh.order.api.v0.models.json._ private[server] trait Matchers[F[_]] extends Http4sDsl[F] { 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[F]): Boolean = req.headers.get(ApiVersionMajor) match { case Some(v) if v.value == "0" => true case _ => false } } object UUIDVal { def unapply(s: String): Option[_root_.java.util.UUID] = scala.util.Try(_root_.java.util.UUID.fromString(s)).toOption } } trait OrderRoutes[F[_]] extends Matchers[F] { implicit def circeJsonDecoder[A](implicit decoder: _root_.io.circe.Decoder[A], sync: Sync[F]) = org.http4s.circe.jsonOf[F, A] implicit def circeJsonEncoder[A](implicit encoder: _root_.io.circe.Encoder[A], sync: Sync[F]) = org.http4s.circe.jsonEncoderOf[F, A] sealed trait GetByOrderIdResponse object GetByOrderIdResponse { case class HTTP200(value: com.faberoh.order.api.v0.models.Order, headers: Seq[org.http4s.Header] = Nil) extends GetByOrderIdResponse case class HTTP404(headers: Seq[org.http4s.Header] = Nil) extends GetByOrderIdResponse case class UndocumentedResponse(response: F[org.http4s.Response[F]]) extends GetByOrderIdResponse } def getByOrderId( _req: org.http4s.Request[F], orderId: _root_.java.util.UUID ): F[GetByOrderIdResponse] sealed trait PostResponse object PostResponse { case class HTTP201(headers: Seq[org.http4s.Header] = Nil) extends PostResponse case class HTTP400(headers: Seq[org.http4s.Header] = Nil) extends PostResponse case class UndocumentedResponse(response: F[org.http4s.Response[F]]) extends PostResponse } def post( _req: org.http4s.Request[F], body: => org.http4s.DecodeResult[F, com.faberoh.order.api.v0.models.Order] ): F[PostResponse] def apiVersionMatch(req: org.http4s.Message[F]): Boolean = ApiVersion(req) def service()(implicit sync: Sync[F]) = org.http4s.HttpService[F] { case _req @ GET -> Root / "orders" / UUIDVal(orderId) if apiVersionMatch(_req) => getByOrderId(_req, orderId).flatMap { case GetByOrderIdResponse.HTTP200(value, headers) => Ok(value, headers: _*) case GetByOrderIdResponse.HTTP404(headers) => NotFound(headers: _*) case GetByOrderIdResponse.UndocumentedResponse(response) => response } case _req @ GET -> Root / "orders" / UUIDVal(orderId) if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") case _req @ POST -> Root / "orders" if apiVersionMatch(_req) => post(_req, _req.attemptAs[com.faberoh.order.api.v0.models.Order]).flatMap { case PostResponse.HTTP201(headers) => Created(headers: _*) case PostResponse.HTTP400(headers) => BadRequest(headers: _*) case PostResponse.UndocumentedResponse(response) => response } case _req @ POST -> Root / "orders" if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") } }