Skip to content
This repository was archived by the owner on Oct 24, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/models/Subscription.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,20 @@ object Subscription {
}
}

def inScheme(subscriberId: Int, schemeId: Int, page: Int) = {
def inScheme(subscriberId: Int, schemeId: Int, page: Int, active: Boolean = true) = {
val offset = page * 10
DB.withConnection { implicit c =>
SQL(
"""
select subscription.* from subscription, topic where subscription.subscriber_id = {sub_id}
and subscription.topic_id = topic.id and topic.scheme_id = {sch_id}
select subscription.* from subscription, topic
where subscription.subscriber_id = {sub_id}
and subscription.topic_id = topic.id
and topic.scheme_id = {sch_id}
and active = {active}
order by created desc
limit 10 offset {offset}
"""
).on('sub_id -> subscriberId, 'sch_id -> schemeId, 'offset -> offset).as(subscrip *)
).on('sub_id -> subscriberId, 'sch_id -> schemeId, 'offset -> offset, 'active -> active).as(subscrip *)
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/unit/SubscriptionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ class SubscriptionSpec extends Specification {
inScheme.contains(s1t5) mustEqual(true)
inScheme.contains(s2t1) mustEqual(false)
inScheme.contains(s2t2) mustEqual(false)
// cancel a scheme - list should reflect only active
s1t5.cancel
val nowInScheme = Subscription.inScheme(sub.id, scheme.id, 0)
nowInScheme.size mustEqual(2)
val canceledInScheme = Subscription.inScheme(sub.id, scheme.id, 0, false)
canceledInScheme.size mustEqual(1)
}
}

Expand Down