diff options
Diffstat (limited to 'core-rest/src/main/scala/xyz/driver/core/rest/directives')
-rw-r--r-- | core-rest/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala | 6 | ||||
-rw-r--r-- | core-rest/src/main/scala/xyz/driver/core/rest/directives/Unmarshallers.scala | 10 |
2 files changed, 16 insertions, 0 deletions
diff --git a/core-rest/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala b/core-rest/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala index 218c9ae..0d60893 100644 --- a/core-rest/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala +++ b/core-rest/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala @@ -28,6 +28,12 @@ trait PathMatchers { } } + def UuidIdInPath[T]: PathMatcher1[UuidId[T]] = + AkkaPathMatchers.JavaUUID.map((id: UUID) => UuidId[T](id)) + + def NumericIdInPath[T]: PathMatcher1[NumericId[T]] = + AkkaPathMatchers.LongNumber.map((id: Long) => NumericId[T](id)) + def NameInPath[T]: PathMatcher1[Name[T]] = new PathMatcher1[Name[T]] { def apply(path: Path) = path match { case Path.Segment(segment, tail) => Matched(tail, Tuple1(Name[T](segment))) diff --git a/core-rest/src/main/scala/xyz/driver/core/rest/directives/Unmarshallers.scala b/core-rest/src/main/scala/xyz/driver/core/rest/directives/Unmarshallers.scala index 6c45d15..93a9a52 100644 --- a/core-rest/src/main/scala/xyz/driver/core/rest/directives/Unmarshallers.scala +++ b/core-rest/src/main/scala/xyz/driver/core/rest/directives/Unmarshallers.scala @@ -16,6 +16,16 @@ trait Unmarshallers { Id[A](UUID.fromString(str).toString) } + implicit def uuidIdUnmarshaller[A]: Unmarshaller[String, UuidId[A]] = + Unmarshaller.strict[String, UuidId[A]] { str => + UuidId[A](UUID.fromString(str)) + } + + implicit def numericIdUnmarshaller[A]: Unmarshaller[Long, NumericId[A]] = + Unmarshaller.strict[Long, NumericId[A]] { x => + NumericId[A](x) + } + implicit def paramUnmarshaller[T](implicit reader: JsonReader[T]): Unmarshaller[String, T] = Unmarshaller.firstOf( Unmarshaller.strict((JsString(_: String)) andThen reader.read), |