diff options
Diffstat (limited to 'src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala b/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala index 183ad9a..218c9ae 100644 --- a/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala +++ b/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala @@ -10,6 +10,7 @@ import akka.http.scaladsl.server.PathMatcher.{Matched, Unmatched} import akka.http.scaladsl.server.{PathMatcher, PathMatcher1, PathMatchers => AkkaPathMatchers} import eu.timepit.refined.collection.NonEmpty import eu.timepit.refined.refineV +import xyz.driver.core.domain.PhoneNumber import xyz.driver.core.time.Time import scala.util.control.NonFatal @@ -70,4 +71,15 @@ trait PathMatchers { Some(Revision[T](string)) } + def PhoneInPath: PathMatcher1[PhoneNumber] = new PathMatcher1[PhoneNumber] { + def apply(path: Path) = path match { + case Path.Segment(segment, tail) => + PhoneNumber + .parse(segment) + .map(parsed => Matched(tail, Tuple1(parsed))) + .getOrElse(Unmatched) + case _ => Unmatched + } + } + } |