/** * 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_15 */ package platform.ibm.com.customer.api.v0.server import org.http4s.dsl._ import platform.ibm.com.customer.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 } } object CustomerNameOptStringMatcher extends OptionalQueryParamDecoderMatcher[String]("customerName") object EmailOptStringMatcher extends OptionalQueryParamDecoderMatcher[String]("email") object FinancialAccountNumberOptUUIDMatcher extends OptionalQueryParamDecoderMatcher[_root_.java.util.UUID]("financialAccountNumber") } trait CustomerRoutes { 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 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: scalaz.concurrent.Task[org.http4s.Response]) extends GetCustomersResponse } def getCustomers( _req: org.http4s.Request, financialAccountNumber: _root_.scala.Option[_root_.java.util.UUID], email: _root_.scala.Option[String], customerName: _root_.scala.Option[String] ): scalaz.concurrent.Task[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: scalaz.concurrent.Task[org.http4s.Response]) extends GetByCustomerNameResponse } def getByCustomerName( _req: org.http4s.Request, customerName: String ): scalaz.concurrent.Task[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: scalaz.concurrent.Task[org.http4s.Response]) extends PostCustomersResponse } def postCustomers( _req: org.http4s.Request, body: => org.http4s.DecodeResult[platform.ibm.com.customer.api.v0.models.CustomerCreateForm] ): scalaz.concurrent.Task[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: scalaz.concurrent.Task[org.http4s.Response]) extends PutByCustomerNameResponse } def putByCustomerName( _req: org.http4s.Request, customerName: String, body: => org.http4s.DecodeResult[platform.ibm.com.customer.api.v0.models.CustomerUpdateForm] ): scalaz.concurrent.Task[PutByCustomerNameResponse] def apiVersionMatch(req: org.http4s.Message): Boolean = ApiVersion(req) def service() = org.http4s.HttpService { 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).putHeaders(headers: _*) case GetCustomersResponse.HTTP404(value, headers) => NotFound(value).putHeaders(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).putHeaders(headers: _*) case GetByCustomerNameResponse.HTTP404(value, headers) => NotFound(value).putHeaders(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).putHeaders(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).putHeaders(headers: _*) case PutByCustomerNameResponse.HTTP404(value, headers) => NotFound(value).putHeaders(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}.") } }