diff --git a/app/adapter/GroupController.scala b/app/adapter/GroupController.scala index 6579c5b..0259b19 100644 --- a/app/adapter/GroupController.scala +++ b/app/adapter/GroupController.scala @@ -1,28 +1,28 @@ package adapter -import javax.inject.Inject - import contract.usecase.PickLeaderUseCase import domain.GroupId +import javax.inject.{Inject, Singleton} import play.api.data.Forms._ import play.api.data._ -import play.api.libs.concurrent.Execution.Implicits.defaultContext -import play.api.mvc.{Action, Controller} +import play.api.mvc.{AbstractController, ControllerComponents} + +import scala.concurrent.ExecutionContext -import scala.concurrent.Future +@Singleton +class GroupController @Inject()(useCase: PickLeaderUseCase, presenter: PickedLeaderPresenter, controllerComponents: ControllerComponents) extends AbstractController(controllerComponents) { -class GroupController @Inject()(useCase: PickLeaderUseCase, presenter: PickedLeaderPresenter) extends Controller { + private implicit lazy val ec: ExecutionContext = defaultExecutionContext - val form = Form( + private val form = Form( mapping( "groupId" -> number )(GroupId.apply)(GroupId.unapply) ) - def pickLeader = Action.async { implicit request => - form.bindFromRequest.fold(_ => Future.successful(BadRequest("not found query parameter: `groupId`")), (groupId: GroupId) => - presenter.response(useCase.execute(groupId)) - ) + def pickLeader = Action.async(parse.form(form)) { implicit request => + val groupId = request.body + presenter.response(useCase.execute(groupId)) } } diff --git a/build.sbt b/build.sbt index 3a96105..fdc627c 100644 --- a/build.sbt +++ b/build.sbt @@ -3,7 +3,7 @@ name := "cleanArchSample" version := "1.0" lazy val scalacSettings = Seq( - scalaVersion := "2.11.7", + scalaVersion := "2.12.8", scalacOptions := Seq( "-feature", "-language:implicitConversions", @@ -15,24 +15,11 @@ lazy val scalacSettings = Seq( ) ) -lazy val playResolvers = Seq( - "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases" -) - lazy val playDependencies = Seq( - jdbc, - cache, - ws, - specs2 % Test -) - -lazy val playSettings = Seq( - routesGenerator := InjectedRoutesGenerator, - unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" ) + guice, + "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % Test ) lazy val `cleanarchsample` = (project in file(".")) - .settings(scalacSettings ++ playSettings: _*) - .settings(resolvers ++= playResolvers) - .settings(libraryDependencies ++= playDependencies) .enablePlugins(PlayScala) + .settings(libraryDependencies ++= playDependencies) diff --git a/conf/application.conf b/conf/application.conf index 39e78e5..70e7582 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -5,57 +5,11 @@ # ~~~~~ # The secret key is used to secure cryptographics functions. # If you deploy your application to several instances be sure to use the same key! -application.secret="%APPLICATION_SECRET%" +play.http.secret.key="%APPLICATION_SECRET%" # The application languages # ~~~~~ -application.langs="en" - -# Global object class -# ~~~~~ -# Define the Global object class for this application. -# Default to Global in the root package. -# application.global=Global - -# Router -# ~~~~~ -# Define the Router object to use for this application. -# This router will be looked up first when the application is starting up, -# so make sure this is the entry point. -# Furthermore, it's assumed your route file is named properly. -# So for an application router like `my.application.Router`, -# you may need to define a router file `conf/my.application.routes`. -# Default to Routes in the root package (and conf/routes) -# application.router=my.application.Routes - -# Database configuration -# ~~~~~ -# You can declare as many datasources as you want. -# By convention, the default datasource is named `default` -# -# db.default.driver=org.h2.Driver -# db.default.url="jdbc:h2:mem:play" -# db.default.user=sa -# db.default.password="" - -# Evolutions -# ~~~~~ -# You can disable evolutions if needed -# evolutionplugin=disabled - -# Logger -# ~~~~~ -# You can also configure logback (http://logback.qos.ch/), -# by providing an application-logger.xml file in the conf directory. - -# Root logger: -logger.root=ERROR - -# Logger used by the framework: -logger.play=INFO - -# Logger provided to your application: -logger.application=DEBUG +play.i18n.langs=["en"] play.modules.enabled += "adapter.AdapterModule" play.modules.enabled += "usecase.UseCaseModule" diff --git a/conf/logback.xml b/conf/logback.xml new file mode 100644 index 0000000..0050290 --- /dev/null +++ b/conf/logback.xml @@ -0,0 +1,22 @@ + + + + + + + %coloredLevel %logger{15} - %message%n%xException{10} + + + + + + + + + + + + + + + diff --git a/project/build.properties b/project/build.properties index 817bc38..c0bab04 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.9 +sbt.version=1.2.8 diff --git a/project/plugins.sbt b/project/plugins.sbt index eb7c9b7..044c172 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,3 @@ logLevel := Level.Warn -resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" - -addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.6") \ No newline at end of file +addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.21")