/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1-dev * User agent: apibuilder app.apibuilder.io/platforminitiative/customer-api/0.0.1-dev/http4s_0_18 */ package platform.ibm.com.customer.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 platform.ibm.com.customer.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 CustomerNameOptStringMatcher extends OptionalQueryParamDecoderMatcher[String]("customerName") object EmailOptStringMatcher extends OptionalQueryParamDecoderMatcher[String]("email") object FinancialAccountNumberOptUUIDMatcher extends OptionalQueryParamDecoderMatcher[_root_.java.util.UUID]("financialAccountNumber") } trait CustomerRoutes[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 GetCustomersResponse object GetCustomersResponse { case class HTTP200(value: Seq[platform.ibm.com.customer.api.v0.models.Customer], headers: Seq[org.http4s.Header] = Nil) extends GetCustomersResponse case class HTTP404(value: Seq[platform.ibm.com.customer.api.v0.models.Error], headers: Seq[org.http4s.Header] = Nil) extends GetCustomersResponse case class UndocumentedResponse(response: F[org.http4s.Response[F]]) extends GetCustomersResponse } def getCustomers( _req: org.http4s.Request[F], financialAccountNumber: _root_.scala.Option[_root_.java.util.UUID], email: _root_.scala.Option[String], customerName: _root_.scala.Option[String] ): F[GetCustomersResponse] sealed trait GetByCustomerNameResponse object GetByCustomerNameResponse { case class HTTP200(value: platform.ibm.com.customer.api.v0.models.Customer, headers: Seq[org.http4s.Header] = Nil) extends GetByCustomerNameResponse case class HTTP404(value: Seq[platform.ibm.com.customer.api.v0.models.Error], headers: Seq[org.http4s.Header] = Nil) extends GetByCustomerNameResponse case class UndocumentedResponse(response: F[org.http4s.Response[F]]) extends GetByCustomerNameResponse } def getByCustomerName( _req: org.http4s.Request[F], customerName: String ): F[GetByCustomerNameResponse] sealed trait PostCustomersResponse object PostCustomersResponse { case class HTTP200(value: platform.ibm.com.customer.api.v0.models.Customer, headers: Seq[org.http4s.Header] = Nil) extends PostCustomersResponse case class UndocumentedResponse(response: F[org.http4s.Response[F]]) extends PostCustomersResponse } def postCustomers( _req: org.http4s.Request[F], body: => org.http4s.DecodeResult[F, platform.ibm.com.customer.api.v0.models.CustomerCreateForm] ): F[PostCustomersResponse] sealed trait PutByCustomerNameResponse object PutByCustomerNameResponse { case class HTTP200(value: platform.ibm.com.customer.api.v0.models.Customer, headers: Seq[org.http4s.Header] = Nil) extends PutByCustomerNameResponse case class HTTP404(value: Seq[platform.ibm.com.customer.api.v0.models.Error], headers: Seq[org.http4s.Header] = Nil) extends PutByCustomerNameResponse case class UndocumentedResponse(response: F[org.http4s.Response[F]]) extends PutByCustomerNameResponse } def putByCustomerName( _req: org.http4s.Request[F], customerName: String, body: => org.http4s.DecodeResult[F, platform.ibm.com.customer.api.v0.models.CustomerUpdateForm] ): F[PutByCustomerNameResponse] def apiVersionMatch(req: org.http4s.Message[F]): Boolean = ApiVersion(req) def service()(implicit sync: Sync[F]) = org.http4s.HttpService[F] { case _req @ GET -> Root / "customers" / "customers" :? FinancialAccountNumberOptUUIDMatcher(financialAccountNumber) +& EmailOptStringMatcher(email) +& CustomerNameOptStringMatcher(customerName) if apiVersionMatch(_req) => getCustomers(_req, financialAccountNumber, email, customerName).flatMap { case GetCustomersResponse.HTTP200(value, headers) => Ok(value, headers: _*) case GetCustomersResponse.HTTP404(value, headers) => NotFound(value, headers: _*) case GetCustomersResponse.UndocumentedResponse(response) => response } case _req @ GET -> Root / "customers" / "customers" :? FinancialAccountNumberOptUUIDMatcher(financialAccountNumber) +& EmailOptStringMatcher(email) +& CustomerNameOptStringMatcher(customerName) if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") case _req @ GET -> Root / "customers" / customerName if apiVersionMatch(_req) => getByCustomerName(_req, customerName).flatMap { case GetByCustomerNameResponse.HTTP200(value, headers) => Ok(value, headers: _*) case GetByCustomerNameResponse.HTTP404(value, headers) => NotFound(value, headers: _*) case GetByCustomerNameResponse.UndocumentedResponse(response) => response } case _req @ GET -> Root / "customers" / customerName if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") case _req @ POST -> Root / "customers" / "customers" if apiVersionMatch(_req) => postCustomers(_req, _req.attemptAs[platform.ibm.com.customer.api.v0.models.CustomerCreateForm]).flatMap { case PostCustomersResponse.HTTP200(value, headers) => Ok(value, headers: _*) case PostCustomersResponse.UndocumentedResponse(response) => response } case _req @ POST -> Root / "customers" / "customers" if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") case _req @ PUT -> Root / "customers" / customerName if apiVersionMatch(_req) => putByCustomerName(_req, customerName, _req.attemptAs[platform.ibm.com.customer.api.v0.models.CustomerUpdateForm]).flatMap { case PutByCustomerNameResponse.HTTP200(value, headers) => Ok(value, headers: _*) case PutByCustomerNameResponse.HTTP404(value, headers) => NotFound(value, headers: _*) case PutByCustomerNameResponse.UndocumentedResponse(response) => response } case _req @ PUT -> Root / "customers" / customerName if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") } }