Skip to content

Commit 3b00e53

Browse files
committed
use jsread
1 parent 92ad977 commit 3b00e53

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

framework/src/main/scala/framework/Validation.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ case class Validation[A](rules: Map[String, A => Boolean]) {
2323
object Validation {
2424
type Result[A] = Either[List[String], A]
2525

26-
def uniqueBy[A, B](as: Iterable[A])(f: A => B): Boolean =
27-
as.groupBy(f).values.forall(_.sizeCompare(1) == 0)
28-
2926
def empty[A]: Validation[A] =
3027
Validation(Map.empty[String, A => Boolean])
3128

server/src/main/scala/server/Router.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import framework.RPC
44

55
@annotation.nowarn
66
object Router extends cask.MainRoutes {
7+
val isProd = sys.env.get("IS_PROD").flatMap(_.toBooleanOption).exists(identity)
8+
79
@cask.get("/")
810
def index() = views.MortgageCalculator.renderDoc
911

1012
@cask.staticFiles("/js/")
11-
def scalaJs() = "web/target/scala-2.13/web-fastopt/"
13+
def scalaJs() = s"web/target/scala-2.13/${if (isProd) "web-opt" else "web-fastopt"}/"
1214

1315
@cask.post("/api", subpath = true)
1416
def routeApi(req: cask.Request) =

web/src/main/scala/views/MortgageCalculator.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ object MortgageCalculator extends framework.Page("mortgage_calculator") {
3838

3939
@nowarn
4040
def calc(element: Element, event: JQueryEvent) = {
41+
import framework.JsRead._
42+
4143
val format = new DecimalFormat("$ #.00");
4244
import api.Mortgage
4345
$("#output").html(
@@ -46,9 +48,9 @@ object MortgageCalculator extends framework.Page("mortgage_calculator") {
4648
).render,
4749
)
4850
for {
49-
amount <- $("#loan").value().asInstanceOf[String].toIntOption
50-
apr <- $("#apr").value().asInstanceOf[String].toFloatOption
51-
years <- $("#years").value().asInstanceOf[String].toIntOption
51+
amount <- $("#loan").value().as[Int]
52+
apr <- $("#apr").value().as[Double]
53+
years <- $("#years").value().as[Int]
5254
mortgage = Mortgage(amount = amount, apr = apr, years = years)
5355
payments <- Mortgage.API.payments(mortgage)
5456
(payment, row) <- payments.zipWithIndex
@@ -64,9 +66,8 @@ object MortgageCalculator extends framework.Page("mortgage_calculator") {
6466
}
6567
}
6668

67-
//TODO: import framework.JsRead._
6869

6970
/*
70-
* Thu, Sep 1: Misc: ScalaCSS, JsRead
71-
* Fri, Sep 2: Tooling (sbt dev)
71+
* Wed, Aug 30: ScalaCSS
72+
* Thu, Sep 1: code review + Screenshot + 2nd API
7273
*/

0 commit comments

Comments
 (0)