Skip to content

Commit

Permalink
YAGNI cleanup, corrected route
Browse files Browse the repository at this point in the history
Fixes #6
Fixes #22
  • Loading branch information
manuelkiessling committed Jan 21, 2016
1 parent c30cc64 commit 1b7236d
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 32 deletions.
7 changes: 1 addition & 6 deletions api/app/controllers/Statistics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ class Statistics(statisticsRepository: Repository[StatisticsModel, String]) exte
)(unlift(StatisticsModel.unapply))

def show(testcaseId: String, n: Int) = Action {
if (n == 1) {
Ok(Json.toJson(List(statisticsRepository.getOneById(testcaseId))))
} else {
Ok(Json.toJson(statisticsRepository.getNById(testcaseId, n)))
}

Ok(Json.toJson(statisticsRepository.getNById(testcaseId, n)))
}

}
17 changes: 0 additions & 17 deletions api/app/repositories/CassandraRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ abstract class CassandraRepository[M <: Model, I](session: Session, tablename: S
extends Repository[M, I] {
def rowToModel(row: Row): M

def getOneRowBySinglePartitionKeyValue(partitionKeyValue: I): Row = {
val selectStmt =
select()
.from(tablename)
.where(QueryBuilder.eq(partitionKeyName, partitionKeyValue))
.limit(1)

val resultSet = session.execute(selectStmt)
val row = resultSet.one()
row
}

def getNBySinglePartitionKeyValue(partitionKeyValue: I, n: Int): ResultSet = {
val selectStmt =
select()
Expand All @@ -32,11 +20,6 @@ abstract class CassandraRepository[M <: Model, I](session: Session, tablename: S
session.execute(selectStmt)
}

override def getOneById(id: I): M = {
val row = getOneRowBySinglePartitionKeyValue(id)
rowToModel(row)
}

override def getNById(id: I, n: Int): List[M] = {
val rows = getNBySinglePartitionKeyValue(id, n).all().toList
rows.map(row => rowToModel(row))
Expand Down
1 change: 0 additions & 1 deletion api/app/repositories/Repository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ package repositories
import models.Model

abstract trait Repository[M <: Model, I] {
def getOneById(id: I): M
def getNById(id: I, n: Int): List[M]
}
2 changes: 1 addition & 1 deletion api/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ GET / controllers.Application.index
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)

# REST API
GET /testresults/:testcaseId/statistics/latest/ controllers.Statistics.show(testcaseId: String, n: Int ?= 1)
GET /testcases/:testcaseId/statistics/latest/ controllers.Statistics.show(testcaseId: String, n: Int ?= 1)
6 changes: 1 addition & 5 deletions api/test/ApplicationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import play.api.{ApplicationLoader, Environment, Mode}
import repositories.Repository

class MockStatisticsRepository extends Repository[StatisticsModel, String] {
override def getOneById(id: String): StatisticsModel = {
StatisticsModel("mocked-testresult-" + id, 987, 123, 456, 789)
}

override def getNById(id: String, n: Int): List[StatisticsModel] = {
List(
StatisticsModel("mocked-testresult-" + id, 987, 123, 456, 789)
Expand Down Expand Up @@ -61,7 +57,7 @@ class ApplicationSpec extends PlaySpec with OneAppPerSuite {
}

"return a JSON array with the latest statistics entry for a given testcase id" in {
val Some(response) = route(FakeRequest(GET, "/testresults/abcd/statistics/latest/?n=1"))
val Some(response) = route(FakeRequest(GET, "/testcases/abcd/statistics/latest/?n=1"))

status(response) mustBe OK
contentType(response) mustBe Some("application/json")
Expand Down
4 changes: 2 additions & 2 deletions api/test/IntegrationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class IntegrationSpec extends PlaySpec with OneBrowserPerSuite with OneServerPer
}

"return a JSON array with the latest statistics entry for a given testcase id" in {
go to "http://localhost:" + port + "/testresults/testcase1/statistics/latest/?n=1"
go to "http://localhost:" + port + "/testcases/testcase1/statistics/latest/?n=1"
pageSource mustBe
"""
|[
Expand All @@ -85,7 +85,7 @@ class IntegrationSpec extends PlaySpec with OneBrowserPerSuite with OneServerPer
}

"return a JSON array with the latest N statistics entries for a given testcase id" in {
go to "http://localhost:" + port + "/testresults/testcase1/statistics/latest/?n=2"
go to "http://localhost:" + port + "/testcases/testcase1/statistics/latest/?n=2"
pageSource mustBe
"""
|[
Expand Down

0 comments on commit 1b7236d

Please sign in to comment.