Skip to content

Commit

Permalink
return challenge status in user leaderboard data
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Feb 18, 2025
1 parent e0aeb47 commit abe79d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/org/maproulette/framework/model/Leaderboard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.maproulette.framework.psql.CommonField
import play.api.libs.json.{Json, Writes}
import play.api.libs.json.JodaWrites._

case class LeaderboardChallenge(id: Long, name: String, activity: Int)
case class LeaderboardChallenge(id: Long, name: String, activity: Int, status: Int)
object LeaderboardChallenge {
implicit val writes: Writes[LeaderboardChallenge] = Json.writes[LeaderboardChallenge]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class LeaderboardRepository @Inject() (override val db: Database) extends Reposi
val leaderboardChallengeParser: RowParser[LeaderboardChallenge] = {
get[Long]("challenge_id") ~
get[String]("challenge_name") ~
get[Int]("activity") map {
case id ~ name ~ activity => {
new LeaderboardChallenge(id, name, activity)
get[Int]("activity") ~
get[Int]("challenges.status") map {
case id ~ name ~ activity ~ status => {
new LeaderboardChallenge(id, name, activity, status)
}
}
}
Expand Down Expand Up @@ -283,7 +284,9 @@ class LeaderboardRepository @Inject() (override val db: Database) extends Reposi
withMRConnection { implicit c =>
query
.build(
"SELECT challenge_id, challenge_name, activity FROM user_top_challenges"
"""SELECT challenge_id, challenge_name, activity, challenges.status
FROM user_top_challenges
JOIN challenges ON challenges.id = user_top_challenges.challenge_id"""
)
.as(this.leaderboardChallengeParser.*)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LeaderboardRepositorySpec(implicit val application: Application) extends F
// Check for everything
val results = this.repository.queryUserLeaderboard(
Query.simple(List()),
userId => List(new LeaderboardChallenge(userId, "name", 1))
userId => List(new LeaderboardChallenge(userId, "name", 1, 1))
)
results.size mustEqual 4

Expand All @@ -49,7 +49,7 @@ class LeaderboardRepositorySpec(implicit val application: Application) extends F
)
)
),
userId => List(new LeaderboardChallenge(userId, "name", 1))
userId => List(new LeaderboardChallenge(userId, "name", 1, 1))
)
results2.size mustEqual 2

Expand All @@ -73,7 +73,7 @@ class LeaderboardRepositorySpec(implicit val application: Application) extends F
)
)
),
userId => List(new LeaderboardChallenge(userId, "name", 1))
userId => List(new LeaderboardChallenge(userId, "name", 1, 1))
)
results3.size mustEqual 2
}
Expand Down

0 comments on commit abe79d5

Please sign in to comment.