Skip to content

Commit

Permalink
rename get to getMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
cornerman committed Jun 25, 2024
1 parent 31fe558 commit f7a14a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions http4sServer/src/main/scala/HttpRpcRoutes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object HttpRpcRoutes {
request.pathInfo.segments match {
case Vector(traitName, methodName) =>
val method = sloth.Method(traitName.decoded(), methodName.decoded())
val result = router(request).get(method).traverse { f =>
val result = router(request).getMethod(method).traverse { f =>
request.as[PickleType].flatMap { payload =>
f(payload) match {
case Left(error) => serverFailureToResponse[F](dsl, onError)(error)
Expand Down Expand Up @@ -56,7 +56,7 @@ object HttpRpcRoutes {
request.pathInfo.segments match {
case Vector(traitName, methodName) =>
val method = sloth.Method(traitName.decoded(), methodName.decoded())
val result = router(request).get(method).traverse { f =>
val result = router(request).getMethod(method).traverse { f =>
request.as[String].flatMap { payload =>
f(payload) match {
case Left(error) => serverFailureToResponse[F](dsl, onError)(error)
Expand Down
18 changes: 9 additions & 9 deletions sloth/src/main/scala/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ import cats.implicits._
import cats.~>

trait Router[PickleType, Result[_]] {
val get: Router.ApiMapping[PickleType, Result]
val getMethod: Router.ApiMapping[PickleType, Result]

def apply(request: Request[PickleType]): Either[ServerFailure, Result[PickleType]] =
get(request.method) match {
getMethod(request.method) match {
case Some(function) => function(request.payload)
case None => Left(ServerFailure.MethodNotFound(request.method))
}

@deprecated("Use get(method) instead", "0.8.0")
def getFunction(path: List[String]): Option[PickleType => Either[ServerFailure, Result[PickleType]]] = get(Request.methodFromList(path))
def getFunction(path: List[String]): Option[PickleType => Either[ServerFailure, Result[PickleType]]] = getMethod(Request.methodFromList(path))

def orElse(collect: Router.ApiMapping[PickleType, Result]): Router[PickleType, Result]
}

class RouterCo[PickleType, Result[_]](private[sloth] val logger: LogHandler[Result], val get: Router.ApiMapping[PickleType, Result])(implicit
class RouterCo[PickleType, Result[_]](private[sloth] val logger: LogHandler[Result], val getMethod: Router.ApiMapping[PickleType, Result])(implicit
private[sloth] val functor: Functor[Result]
) extends Router[PickleType, Result] with PlatformSpecificRouterCo[PickleType, Result] {

def orElse(collect: Router.ApiMapping[PickleType, Result]): RouterCo[PickleType, Result] = new RouterCo(logger, request => get(request).orElse(collect(request)))
def orElse(collect: Router.ApiMapping[PickleType, Result]): RouterCo[PickleType, Result] = new RouterCo(logger, request => getMethod(request).orElse(collect(request)))

def mapResult[R[_]: Functor](f: Result ~> R, logger: LogHandler[R] = LogHandler.empty[R]): Router[PickleType, R] = new RouterCo(logger, request => get(request).map { case v => v.map(_.map(f.apply)) })
def mapResult[R[_]: Functor](f: Result ~> R, logger: LogHandler[R] = LogHandler.empty[R]): Router[PickleType, R] = new RouterCo(logger, request => getMethod(request).map { case v => v.map(_.map(f.apply)) })
}

class RouterContra[PickleType, Result[_]](private[sloth] val logger: LogHandler[Result], val get: Router.ApiMapping[PickleType, Result])(implicit
class RouterContra[PickleType, Result[_]](private[sloth] val logger: LogHandler[Result], val getMethod: Router.ApiMapping[PickleType, Result])(implicit
private[sloth] val routerHandler: RouterContraHandler[Result]
) extends Router[PickleType, Result] with PlatformSpecificRouterContra[PickleType, Result] {

def orElse(collect: Router.ApiMapping[PickleType, Result]): RouterContra[PickleType, Result] = new RouterContra(logger, request => get(request).orElse(collect(request)))
def orElse(collect: Router.ApiMapping[PickleType, Result]): RouterContra[PickleType, Result] = new RouterContra(logger, request => getMethod(request).orElse(collect(request)))

def mapResult[R[_]: RouterContraHandler](f: Result ~> R, logger: LogHandler[R] = LogHandler.empty[R]): Router[PickleType, R] = new RouterContra(logger, request => get(request).map { case v => v.map(_.map(f.apply)) })
def mapResult[R[_]: RouterContraHandler](f: Result ~> R, logger: LogHandler[R] = LogHandler.empty[R]): Router[PickleType, R] = new RouterContra(logger, request => getMethod(request).map { case v => v.map(_.map(f.apply)) })
}

object Router {
Expand Down

0 comments on commit f7a14a1

Please sign in to comment.