From 374ea231b13abc7510fadb5399811e5233d017c3 Mon Sep 17 00:00:00 2001 From: Manuel Fuchs Date: Wed, 5 Apr 2023 12:29:59 +0200 Subject: [PATCH] Add convert endpoint --- app/controllers/Application.scala | 10 ++++++++++ build.sbt | 3 ++- conf/routes | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/Application.scala b/app/controllers/Application.scala index 0fbccb4..dcebcd9 100644 --- a/app/controllers/Application.scala +++ b/app/controllers/Application.scala @@ -4,6 +4,9 @@ import javax.inject._ import play.api._ import play.api.db.Database import play.api.mvc._ +import org.jscience.physics.amount.Amount +import org.jscience.physics.model.RelativisticModel +import javax.measure.unit.SI @Singleton class Application @Inject()(val controllerComponents: ControllerComponents, val database: Database) extends BaseController { @@ -12,6 +15,13 @@ class Application @Inject()(val controllerComponents: ControllerComponents, val Ok(views.html.index()) } + def convert(): Action[AnyContent] = Action { implicit request: Request[AnyContent] => + RelativisticModel.select() + val energy = Amount.valueOf("12 GeV"); + + Ok("E=mc^2: " + energy + " = " + energy.to(SI.KILOGRAM)) + } + def db(): Action[AnyContent] = Action { implicit request: Request[AnyContent] => // In this getting started app, we don't use a custom execution context to keep the code and configuration simple. // For real-world apps, consult the Play documentation on how to configure custom contexts and how to use them: diff --git a/build.sbt b/build.sbt index 6f0bb02..5496b9f 100644 --- a/build.sbt +++ b/build.sbt @@ -13,7 +13,8 @@ libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0 libraryDependencies ++= Seq( "com.google.inject" % "guice" % "5.1.0", "com.google.inject.extensions" % "guice-assistedinject" % "5.1.0", - "org.postgresql" % "postgresql" % "42.6.0" + "org.postgresql" % "postgresql" % "42.6.0", + "org.jscience" % "jscience" % "4.3.1" ) // Adds additional packages into Twirl diff --git a/conf/routes b/conf/routes index b22a4d5..dd0021b 100644 --- a/conf/routes +++ b/conf/routes @@ -5,6 +5,7 @@ GET / controllers.Application.index() GET /database controllers.Application.db() +GET /convert controllers.Application.convert() # Map static resources from the /public folder to the /assets URL path GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)