From e45e981634c1bdccd02bae4e37fac1c1e654cdfe Mon Sep 17 00:00:00 2001 From: vlad Date: Mon, 25 Jul 2016 15:00:39 -0400 Subject: Some more JSON formatters and json,rest packages rearranged --- src/main/scala/com/drivergrp/core/rest.scala | 54 +--------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) (limited to 'src/main/scala/com/drivergrp/core/rest.scala') diff --git a/src/main/scala/com/drivergrp/core/rest.scala b/src/main/scala/com/drivergrp/core/rest.scala index 914e1ec..3f3a68e 100644 --- a/src/main/scala/com/drivergrp/core/rest.scala +++ b/src/main/scala/com/drivergrp/core/rest.scala @@ -2,21 +2,18 @@ package com.drivergrp.core import akka.actor.ActorSystem import akka.http.scaladsl.Http -import akka.http.scaladsl.model.Uri.Path import akka.http.scaladsl.model.{HttpRequest, HttpResponse} -import akka.http.scaladsl.server.PathMatcher.Matched import akka.http.scaladsl.server.{Directive, _} import akka.http.scaladsl.util.FastFuture._ import akka.stream.ActorMaterializer import akka.util.Timeout import com.drivergrp.core.logging.Logger import com.drivergrp.core.stats.Stats -import com.drivergrp.core.time.{Time, TimeRange} +import com.drivergrp.core.time.TimeRange import com.drivergrp.core.time.provider.TimeProvider import com.github.swagger.akka.model._ import com.github.swagger.akka.{HasActorSystem, SwaggerHttpService} import com.typesafe.config.Config -import spray.json.{DeserializationException, JsNumber, JsObject, JsString, JsValue, RootJsonFormat} import scala.concurrent.duration._ import scala.concurrent.{ExecutionContext, Future} @@ -24,7 +21,6 @@ import scala.language.postfixOps import scala.util.{Failure, Success, Try} import scalaz.{Failure => _, Success => _, _} - object rest { trait RestService { @@ -68,54 +64,6 @@ object rest { } } - object basicFormats { - - def IdInPath[T]: PathMatcher1[Id[T]] = - PathMatcher("""[+-]?\d*""".r) flatMap { string ⇒ - try Some(Id[T](string.toLong)) catch { case _: IllegalArgumentException ⇒ None } - } - - implicit def idFormat[T] = new RootJsonFormat[Id[T]] { - def write(id: Id[T]) = JsNumber(id) - - def read(value: JsValue) = value match { - case JsNumber(id) => Id[T](id.toLong) - case _ => throw new DeserializationException("Id expects number") - } - } - - def NameInPath[T]: PathMatcher1[Name[T]] = new PathMatcher1[Name[T]] { - def apply(path: Path) = Matched(Path.Empty, Tuple1(Name[T](path.toString))) - } - - implicit def nameFormat[T] = new RootJsonFormat[Name[T]] { - def write(name: Name[T]) = JsString(name) - - def read(value: JsValue): Name[T] = value match { - case JsString(name) => Name[T](name) - case _ => throw new DeserializationException("Name expects string") - } - } - - def TimeInPath: PathMatcher1[Time] = - PathMatcher("""[+-]?\d*""".r) flatMap { string ⇒ - try Some(Time(string.toLong)) catch { case _: IllegalArgumentException ⇒ None } - } - - implicit val timeFormat = new RootJsonFormat[Time] { - def write(time: Time) = JsObject("timestamp" -> JsNumber(time.millis)) - - def read(value: JsValue): Time = value match { - case JsObject(fields) => - fields.get("timestamp").flatMap { - case JsNumber(millis) => Some(Time(millis.toLong)) - case _ => None - }.getOrElse(throw new DeserializationException("Time expects number")) - case _ => throw new DeserializationException("Time expects number") - } - } - } - trait OptionTDirectives { /** -- cgit v1.2.3