aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakob Odersky <jakob@driver.xyz>2017-08-07 15:47:02 -0700
committerJakob Odersky <jakob@driver.xyz>2017-08-16 19:26:10 -0700
commit7f3e788642b1d3946fccc0e13d3c3121034d9d7d (patch)
tree8282ef04cd0ad45de25c6e380cb6ea39b958ae06 /src
parent8657a5cfa8695607feb9025ebdbfbd13a5b4a8a8 (diff)
downloadrest-query-7f3e788642b1d3946fccc0e13d3c3121034d9d7d.tar.gz
rest-query-7f3e788642b1d3946fccc0e13d3c3121034d9d7d.tar.bz2
rest-query-7f3e788642b1d3946fccc0e13d3c3121034d9d7d.zip
Add path matchers for custom id types
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala b/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala
index 0fe1f73..7a6266f 100644
--- a/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala
+++ b/src/main/scala/xyz/driver/pdsuicommon/http/Directives.scala
@@ -3,7 +3,7 @@ package xyz.driver.pdsuicommon.http
import akka.http.scaladsl.marshalling._
import akka.http.scaladsl.server.Directive1
import akka.http.scaladsl.server.Directives._
-import akka.http.scaladsl.server.Route
+import akka.http.scaladsl.server.{PathMatcher1, PathMatchers}
import akka.http.scaladsl.model._
import xyz.driver.core.rest.AuthorizedServiceRequestContext
import xyz.driver.core.rest.ContextHeaders
@@ -14,6 +14,7 @@ import xyz.driver.pdsuicommon.error.DomainError._
import xyz.driver.pdsuicommon.error.ErrorsResponse.ResponseError
import xyz.driver.pdsuicommon.parsers._
import xyz.driver.pdsuicommon.db.{Pagination, Sorting, SearchFilterExpr}
+import xyz.driver.pdsuicommon.domain._
import scala.util._
import scala.concurrent._
@@ -38,6 +39,15 @@ trait Directives {
}
}
+ def StringIdInPath[T]: PathMatcher1[StringId[T]] =
+ PathMatchers.Segment.map((id) => StringId(id.toString.toLowerCase))
+
+ def LongIdInPath[T]: PathMatcher1[LongId[T]] =
+ PathMatchers.LongNumber.map((id) => LongId(id))
+
+ def UuidIdInPath[T]: PathMatcher1[UuidId[T]] =
+ PathMatchers.JavaUUID.map((id) => UuidId(id))
+
@annotation.implicitNotFound("An ApiExtractor of ${Reply} to ${Api} is required to complete service replies.")
trait ApiExtractor[Reply, Api] extends PartialFunction[Reply, Api]
object ApiExtractor {