-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
159 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,39 @@ | ||
inThisBuild( | ||
List( | ||
name := "joi-energy-scala", | ||
version := "0.1", | ||
scalaVersion := "2.13.10", | ||
Compile / mainClass := Some("com.tw.energy.WebApp"), | ||
run / mainClass := Some("com.tw.energy.WebApp"), | ||
), | ||
) | ||
scalaVersion := "3.3.0" | ||
)) | ||
|
||
|
||
val circeVersion = "0.14.5" | ||
val akkaVersion = "2.6.20" | ||
val akkaHttpVersion = "10.2.10" | ||
val akkaVersion = "2.8.3" | ||
val akkaHttpVersion = "10.5.2" | ||
val akkaHttpCirceVersion = "1.39.2" | ||
val scalaTestVersion = "3.2.15" | ||
val scalaTestVersion = "3.2.16" | ||
|
||
libraryDependencies += "com.typesafe.akka" %% "akka-http" % akkaHttpVersion // Http Server library: https://doc.akka.io/docs/akka-http/current/server-side/index.html | ||
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % akkaVersion // Required by akka-http | ||
lazy val circeCore = "io.circe" %% "circe-core" % circeVersion | ||
lazy val circeGeneric = "io.circe" %% "circe-generic" % circeVersion | ||
lazy val circeParser = "io.circe" %% "circe-parser" % circeVersion | ||
lazy val akkaHttp = "com.typesafe.akka" %% "akka-http" % akkaHttpVersion // Http Server library: https://doc.akka.io/docs/akka-http/current/server-side/index.html | ||
lazy val akkaStream = "com.typesafe.akka" %% "akka-stream" % akkaVersion // Required by akka-http | ||
// lazy val akkaHttpCirce = "de.heikoseeberger" %% "akka-http-circe" % akkaHttpCirceVersion | ||
|
||
//json library: https://circe.github.io/circe/ | ||
libraryDependencies += "io.circe" %% "circe-core" % circeVersion | ||
libraryDependencies += "io.circe" %% "circe-generic" % circeVersion | ||
libraryDependencies += "io.circe" %% "circe-parser" % circeVersion | ||
libraryDependencies += "de.heikoseeberger" %% "akka-http-circe" % akkaHttpCirceVersion | ||
lazy val scalaTest = "org.scalatest" %% "scalatest" % scalaTestVersion % Test // Test framework: http://www.scalatest.org/ | ||
lazy val akkaHttpTestKit = "com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test // utilities to test routes: https://doc.akka.io/docs/akka-http/current/routing-dsl/testkit.html | ||
lazy val akkaTestKit = "com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test // required by akka-http-testkit | ||
|
||
libraryDependencies += "org.scalatest" %% "scalatest" % scalaTestVersion % Test //Test framework: http://www.scalatest.org/ | ||
libraryDependencies += "com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test //utilities to test routes: https://doc.akka.io/docs/akka-http/current/routing-dsl/testkit.html | ||
libraryDependencies += "com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test //required by akka-http-testkit | ||
libraryDependencies ++= List( | ||
akkaHttp, | ||
akkaStream, | ||
akkaTestKit, | ||
akkaHttpTestKit, | ||
circeCore, | ||
circeGeneric, | ||
circeParser, | ||
scalaTest | ||
) | ||
|
||
scalacOptions ++= Seq("-deprecation", "-feature") | ||
|
||
//conflictWarning := ConflictWarning.default | ||
conflictManager := ConflictManager.latestRevision |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version = 1.8.2 | ||
sbt.version = 1.9.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,42 @@ | ||
package com.tw.energy.controller | ||
|
||
import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport | ||
import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} | ||
import akka.http.scaladsl.model.{HttpCharsets, MediaTypes} | ||
import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller} | ||
import akka.http.scaladsl.util.FastFuture | ||
import akka.util.ByteString | ||
import io.circe.{Decoder, Encoder, Error} | ||
import io.circe.syntax.* | ||
import io.circe.parser.decode | ||
|
||
trait JsonSupport extends FailFastCirceSupport { | ||
} | ||
import java.nio.charset.StandardCharsets | ||
|
||
/** | ||
* Rudimentary support for handling json marshalling and unmarshalling JSON using Circe. To use, | ||
* ensure that `Encoder` and `Decoder` implicits are available for the type you want to handle. For example, | ||
* by `import io.circe.generic.auto.*` to gain automatic encoder and decoder generation for case classes. | ||
* | ||
* Inspired by Heiko Seeberger's code at https://github.com/hseeberger/akka-http-json/tree/master/akka-http-circe/src - but | ||
* which doesn't yet support Scala 3 out of the box. | ||
*/ | ||
trait JsonSupport { | ||
|
||
implicit def jsonToEntityMarshaller[A](implicit encoder: Encoder[A]): ToEntityMarshaller[A] = | ||
Marshaller.StringMarshaller.wrap(MediaTypes.`application/json`)((a:A) => a.asJson.noSpaces) | ||
|
||
implicit def jsonFromEntityUnmarshaller[A](implicit decoder: Decoder[A]): FromEntityUnmarshaller[A] = { | ||
Unmarshaller | ||
.byteStringUnmarshaller | ||
.forContentTypes(MediaTypes.`application/json`) | ||
.andThen(stringViaDecoderUnmarshaller) | ||
} | ||
|
||
private def stringViaDecoderUnmarshaller[A](implicit decoder: Decoder[A]): Unmarshaller[ByteString, A] = | ||
Unmarshaller.withMaterializer[ByteString, A](_ => _ => { bs => | ||
decode[A](bs.decodeString(StandardCharsets.UTF_8)).fold( | ||
(error: Error) => FastFuture.failed(error), | ||
(a: A) => FastFuture.successful(a) | ||
) | ||
}) | ||
|
||
} |
11 changes: 5 additions & 6 deletions
11
src/main/scala/com/tw/energy/controller/MeterReadingController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
src/main/scala/com/tw/energy/controller/PricePlanComparatorController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/scala/com/tw/energy/service/MeterReadingService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.