aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala
diff options
context:
space:
mode:
authorvlad <vlad@drivergrp.com>2016-07-28 13:54:06 -0700
committervlad <vlad@drivergrp.com>2016-07-28 13:54:06 -0700
commit0b3910c99854717282150bd4462c745b4008c7ae (patch)
tree798b42ea693ff2947bc5ea454d4c99c0dc8092f7 /src/main/scala
parentc6b4c8a713f573dc0bcf729d1b1d2803dad4b98b (diff)
downloaddriver-core-0b3910c99854717282150bd4462c745b4008c7ae.tar.gz
driver-core-0b3910c99854717282150bd4462c745b4008c7ae.tar.bz2
driver-core-0b3910c99854717282150bd4462c745b4008c7ae.zip
Removed monadic directives + Fixed timezones for textual time + Explicit Swagger host provision
Diffstat (limited to 'src/main/scala')
-rw-r--r--src/main/scala/com/drivergrp/core/app.scala4
-rw-r--r--src/main/scala/com/drivergrp/core/rest.scala24
-rw-r--r--src/main/scala/com/drivergrp/core/time.scala10
3 files changed, 10 insertions, 28 deletions
diff --git a/src/main/scala/com/drivergrp/core/app.scala b/src/main/scala/com/drivergrp/core/app.scala
index ebd4213..24b2120 100644
--- a/src/main/scala/com/drivergrp/core/app.scala
+++ b/src/main/scala/com/drivergrp/core/app.scala
@@ -53,9 +53,7 @@ object app {
protected def bindHttp(modules: Seq[Module]): Unit = {
val serviceTypes = modules.flatMap(_.routeTypes)
- val swaggerService = new Swagger(actorSystem, serviceTypes, config) {
- override val host = interface + ":" + port
- }
+ val swaggerService = new Swagger(interface + ":" + port, actorSystem, serviceTypes, config)
val swaggerRoutes = swaggerService.routes ~ swaggerService.swaggerUI
val versionRt = versionRoute(version, buildNumber)
diff --git a/src/main/scala/com/drivergrp/core/rest.scala b/src/main/scala/com/drivergrp/core/rest.scala
index 3f3a68e..91e9d3b 100644
--- a/src/main/scala/com/drivergrp/core/rest.scala
+++ b/src/main/scala/com/drivergrp/core/rest.scala
@@ -3,8 +3,6 @@ package com.drivergrp.core
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{HttpRequest, HttpResponse}
-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
@@ -18,8 +16,8 @@ import com.typesafe.config.Config
import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future}
import scala.language.postfixOps
-import scala.util.{Failure, Success, Try}
-import scalaz.{Failure => _, Success => _, _}
+import scala.util.{Failure, Success}
+import scalaz.{Failure => _, Success => _}
object rest {
@@ -64,29 +62,15 @@ object rest {
}
}
- trait OptionTDirectives {
-
- /**
- * "Unwraps" a `OptionT[Future, T]` and runs the inner route after future
- * completion with the future's value as an extraction of type `Try[T]`.
- * Copied akka-http code with added `.run` call on `OptionT`.
- */
- def onComplete[T](optionT: OptionT[Future, T]): Directive1[Try[Option[T]]] =
- Directive { inner ⇒ ctx ⇒
- optionT.run.fast.transformWith(t ⇒ inner(Tuple1(t))(ctx))(ctx.executionContext)
- }
- }
-
-
import scala.reflect.runtime.universe._
- class Swagger(override val actorSystem: ActorSystem,
+ class Swagger(override val host: String,
+ override val actorSystem: ActorSystem,
override val apiTypes: Seq[Type],
val config: Config) extends SwaggerHttpService with HasActorSystem {
val materializer = ActorMaterializer()(actorSystem)
- override val host = "localhost:8080" // the url of your api, not swagger's json endpoint
override val basePath = config.getString("swagger.basePath")
override val apiDocsPath = config.getString("swagger.docsPath")
diff --git a/src/main/scala/com/drivergrp/core/time.scala b/src/main/scala/com/drivergrp/core/time.scala
index ebe0071..9bafb00 100644
--- a/src/main/scala/com/drivergrp/core/time.scala
+++ b/src/main/scala/com/drivergrp/core/time.scala
@@ -1,7 +1,7 @@
package com.drivergrp.core
import java.text.SimpleDateFormat
-import java.util.{Calendar, Date, GregorianCalendar}
+import java.util._
import scala.concurrent.duration._
@@ -41,11 +41,11 @@ object time {
}.getTime.getTime)
}
- def textualDate(time: Time): String =
- new SimpleDateFormat("MMMM d, yyyy").format(new Date(time.millis))
+ def textualDate(timezone: TimeZone)(time: Time): String =
+ make(new SimpleDateFormat("MMMM d, yyyy"))(_.setTimeZone(timezone)).format(new Date(time.millis))
- def textualTime(time: Time): String =
- new SimpleDateFormat("MMM dd, yyyy hh:mm:ss a").format(new Date(time.millis))
+ def textualTime(timezone: TimeZone)(time: Time): String =
+ make(new SimpleDateFormat("MMM dd, yyyy hh:mm:ss a"))(_.setTimeZone(timezone)).format(new Date(time.millis))
object provider {