From c735f5344da4bdd23dabba0e6006f7e241494b3c Mon Sep 17 00:00:00 2001 From: Jeremy Prevost Date: Mon, 17 Aug 2015 15:23:29 -0400 Subject: [PATCH] Provides links to Interests by Scheme on Subscriber Dashboard closes #313 --- app/models/Subscriber.scala | 9 +++++++++ app/views/subscriber/dashboard.scala.html | 9 +++++++++ test/unit/SubscriberSpec.scala | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/app/models/Subscriber.scala b/app/models/Subscriber.scala index 17c8ee8..08afb97 100644 --- a/app/models/Subscriber.scala +++ b/app/models/Subscriber.scala @@ -37,6 +37,15 @@ case class Subscriber(id: Int, // DB key } } + def interestCountIn(schemeTag: String) = { + DB.withConnection { implicit c => + SQL("""select COUNT(*) from interest + where subscriber_id = {sub_id} + and scheme_tag = {stag}""") + .on('sub_id -> id, 'stag -> schemeTag).as(scalar[Long].single) + } + } + def interestIn(schemeTag: String) = { DB.withConnection { implicit c => SQL("select * from interest where subscriber_id = {sub_id} and scheme_tag = {stag}") diff --git a/app/views/subscriber/dashboard.scala.html b/app/views/subscriber/dashboard.scala.html index 953ffe8..58facf0 100644 --- a/app/views/subscriber/dashboard.scala.html +++ b/app/views/subscriber/dashboard.scala.html @@ -66,6 +66,15 @@

Destinations

Add a new destination + +

Interests by Scheme

+ @for(s <- Scheme.withGentype("topic").filter(_.tag != "meta").sortWith(_.tag.toLowerCase < _.tag.toLowerCase)) { +
  • + @sub.interestCountIn(s.tag) + @s.tag + +
  • + }
    diff --git a/test/unit/SubscriberSpec.scala b/test/unit/SubscriberSpec.scala index 25ba433..6b2b09e 100644 --- a/test/unit/SubscriberSpec.scala +++ b/test/unit/SubscriberSpec.scala @@ -169,6 +169,23 @@ class SubscriberSpec extends Specification { } } + "#interestsCountIn" in { + running(FakeApplication(additionalConfiguration = inMemoryDatabase())) { + Subscriber.all must haveSize(0) + val u = User.make("bob", "bob@example.com", "pwd", "role1") + val s = Subscriber.make(u.id, "Sub Name", "cat", "contact", Some("link"), Some("logo")) + s.interests must haveSize(0) + val sch1 = Scheme.make("tag", "gentype", "cat", "desc", Some("link"), Some("logo")) + val sch2 = Scheme.make("tag1", "gentype", "cat", "desc", Some("link"), Some("logo")) + s.interestCountIn("tag") must equalTo(0) + s.interestCountIn("tag1") must equalTo(0) + s.addInterest(sch1, "MIT", true) + s.addInterest(sch1, "Stanford", false) + s.interestCountIn("tag") must equalTo(2) + s.interestCountIn("tag1") must equalTo(0) + } + } + "#interestIn" in { running(FakeApplication(additionalConfiguration = inMemoryDatabase())) { Subscriber.all must haveSize(0)