Skip to content

Commit

Permalink
simple-app: Update to match 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexITC committed Dec 10, 2018
1 parent 90b305e commit 95b7727
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ class DummyAuthenticatorService extends AbstractAuthenticatorService[Int] {
Future.successful(result)
}
}

12 changes: 6 additions & 6 deletions examples/simple-app/app/controllers/HelloWorldController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ package controllers
import javax.inject.Inject

import com.alexitc.example.UserError
import com.alexitc.playsonify.models.{AuthenticatedContext, PublicContext, PublicContextWithModel}
import controllers.common.{MyJsonController, MyJsonControllerComponents}
import org.scalactic.{Bad, Every, Good}
import play.api.i18n.Lang
import play.api.libs.json.{Json, Reads, Writes}

import scala.concurrent.Future

class HelloWorldController @Inject() (components: MyJsonControllerComponents)
extends MyJsonController(components) {

def hello = publicWithInput { context: PublicContextWithModel[Person, Lang] =>
import Context._

def hello = publicInput { context: HasModel[Person] =>
val msg = s"Hello ${context.model.name}, you are ${context.model.age} years old"
val helloMessage = HelloMessage(msg)
val goodResult = Good(helloMessage)

Future.successful(goodResult)
}

def authenticatedHello = authenticatedNoInput { context: AuthenticatedContext[Int, Lang] =>
def authenticatedHello = authenticated { context: Authenticated =>
val msg = s"Hello user with id ${context.auth}"
val helloMessage = HelloMessage(msg)
val goodResult = Good(helloMessage)

Future.successful(goodResult)
}

def failedHello = publicNoInput[HelloMessage] { context: PublicContext[Lang] =>
def failedHello = public[HelloMessage] { context: Context =>
val errors = Every(
UserError.UserEmailIncorrect,
UserError.UserAlreadyExist,
Expand All @@ -40,7 +40,7 @@ class HelloWorldController @Inject() (components: MyJsonControllerComponents)
Future.successful(badResult)
}

def exceptionHello = publicNoInput[HelloMessage] { context: PublicContext[Lang] =>
def exceptionHello = public[HelloMessage] { context: Context =>
Future.failed(new RuntimeException("database unavailable"))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package controllers.common

import com.alexitc.playsonify.models.{ErrorId, ServerError}
import com.alexitc.playsonify.models.ServerError
import com.alexitc.playsonify.play.AbstractJsonController
import org.slf4j.LoggerFactory

abstract class MyJsonController(components: MyJsonControllerComponents) extends AbstractJsonController(components) {

protected val logger = LoggerFactory.getLogger(this.getClass)

override protected def onServerError(error: ServerError, errorId: ErrorId): Unit = {
logger.error(s"Unexpected internal error = ${errorId.string}", error.cause)
override protected def onServerError(error: ServerError): Unit = {
error.cause match {
case Some(cause) =>
logger.error(s"Unexpected internal error, id = ${error.id.string}, error = $error", cause)

case None =>
logger.error(s"Unexpected internal error, id = ${error.id.string}, error = $error}")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import javax.inject.Inject

import com.alexitc.example.DummyAuthenticatorService
import com.alexitc.playsonify.play.{I18nPlayService, JsonControllerComponents, PublicErrorRenderer}
import play.api.i18n.Lang
import play.api.mvc.MessagesControllerComponents

import scala.concurrent.ExecutionContext
Expand All @@ -15,4 +14,4 @@ class MyJsonControllerComponents @Inject() (
override val publicErrorRenderer: PublicErrorRenderer,
override val i18nService: I18nPlayService,
override val authenticatorService: DummyAuthenticatorService)
extends JsonControllerComponents[Int, Lang]
extends JsonControllerComponents[Int]
3 changes: 2 additions & 1 deletion examples/simple-app/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ scalaVersion := "2.12.2"
lazy val root = (project in file("."))
.enablePlugins(PlayScala)

val playsonifyVersion = "2.0.0-SNAPSHOT"
val playsonifyVersion = "2.0.0"

libraryDependencies ++= Seq(guice)

libraryDependencies ++= Seq(
"com.alexitc" %% "playsonify-core" % playsonifyVersion,
"com.alexitc" %% "playsonify-play" % playsonifyVersion,
"com.alexitc" %% "playsonify-sql" % playsonifyVersion,
"com.alexitc" %% "playsonify-play-test" % playsonifyVersion % Test
)

Expand Down
4 changes: 4 additions & 0 deletions examples/simple-app/conf/messages
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
user.error.alreadyExist=The user already exist
user.error.notFound=The user was not found
user.error.incorrectEmail=The email format is incorrect

auth.error.invalidToken=The authentication token is invalid

error.internal=Internal error

0 comments on commit 95b7727

Please sign in to comment.