diff --git a/app/org/maproulette/controllers/api/DataController.scala b/app/org/maproulette/controllers/api/DataController.scala index 820b407f..c819d743 100644 --- a/app/org/maproulette/controllers/api/DataController.scala +++ b/app/org/maproulette/controllers/api/DataController.scala @@ -10,9 +10,11 @@ import org.maproulette.data._ import org.maproulette.framework.model.Challenge import org.maproulette.models.dal.ChallengeDAL import org.maproulette.session.{SearchParameters, SessionManager} +import anorm.{SQL, SqlParser} +import anorm.SqlParser.scalar import org.maproulette.permissions.Permission import org.maproulette.utils.Utils -import play.api.libs.json.Json.JsValueWrapper +import play.api.libs.json.Json.{JsValueWrapper, toJsObject} import play.api.libs.json._ import play.api.mvc._ @@ -126,12 +128,14 @@ class DataController @Inject() ( def getChallengeSummary( id: Long, priority: String, - includeByPriority: Boolean = false + includeByPriority: Boolean = false, + virtualChallengeId: Long ): Action[AnyContent] = Action.async { implicit request => this.sessionManager.authenticatedRequest { _ => SearchParameters.withSearch { implicit params => val response = this.dataManager.getChallengeSummary( challengeId = Some(id), + virtualChallengeId = Some(virtualChallengeId), priority = Utils.toIntList(priority), params = Some(params) ) @@ -274,6 +278,7 @@ class DataController @Inject() ( this.dataManager.getChallengeSummary( projectList, None, + Some(0), length, start, orderColumnName, diff --git a/app/org/maproulette/data/DataManager.scala b/app/org/maproulette/data/DataManager.scala index 5018780c..20691eae 100644 --- a/app/org/maproulette/data/DataManager.scala +++ b/app/org/maproulette/data/DataManager.scala @@ -5,9 +5,9 @@ package org.maproulette.data import java.sql.Connection - import anorm.SqlParser._ import anorm._ + import javax.inject.{Inject, Singleton} import org.joda.time.DateTime import org.maproulette.Config @@ -19,6 +19,7 @@ import org.maproulette.session.SearchParameters import org.maproulette.utils.BoundingBoxFinder import play.api.Application import play.api.db.Database +import play.api.libs.json.{JsObject, Json} case class ActionSummary( total: Int, @@ -317,6 +318,7 @@ class DataManager @Inject() ( def getChallengeSummary( projectList: Option[List[Long]] = None, challengeId: Option[Long] = None, + virtualChallengeId: Option[Long] = None, limit: Int = (-1), offset: Int = 0, orderColumn: Option[String] = None, @@ -327,6 +329,18 @@ class DataManager @Inject() ( params: Option[SearchParameters] = None ): List[ChallengeSummary] = { this.db.withConnection { implicit c => + val virtualParams = virtualChallengeId.flatMap { id => + if (id != 0) { + val result = + SQL("SELECT search_parameters FROM virtual_challenges WHERE id = {virtualChallengeId}") + .on("virtualChallengeId" -> id) + .as(SqlParser.str("search_parameters").singleOpt) + result.map(Json.parse).flatMap(_.validate[SearchParameters].asOpt) + } else { + None + } + } + val parser = for { id <- int("tasks.parent_id") name <- str("challenges.name") @@ -363,9 +377,16 @@ class DataManager @Inject() ( ) ) val searchParams = SearchParameters.withDefaultAllTaskStatuses( - params match { - case Some(p) => p - case None => new SearchParameters() + if (virtualParams.isDefined) { + virtualParams match { + case Some(p) => p + case None => new SearchParameters() + } + } else { + params match { + case Some(p) => p + case None => new SearchParameters() + } } ) @@ -392,6 +413,7 @@ class DataManager @Inject() ( this.paramsOwner(searchParams, searchFilters) this.paramsReviewer(searchParams, searchFilters) this.paramsMapper(searchParams, searchFilters) + this.paramsBoundingGeometries(searchParams, searchFilters) // The percentage columns are a bit of a hack simply so that we can order by the percentages. // It won't decrease performance as this is simple basic math calculations, but it certainly diff --git a/conf/v2_route/data.api b/conf/v2_route/data.api index dd08e110..d1a3e1ac 100644 --- a/conf/v2_route/data.api +++ b/conf/v2_route/data.api @@ -25,6 +25,6 @@ GET /data/status/summary @org.maproulette.controllers ### NoDocs ### GET /data/challenge/:challengeId/propertyKeys @org.maproulette.controllers.api.DataController.getPropertyKeys(challengeId:Long) ### NoDocs ### -GET /data/challenge/:challengeId @org.maproulette.controllers.api.DataController.getChallengeSummary(challengeId:Long, priority:String ?= "", includeByPriority:Boolean ?= false) +GET /data/challenge/:challengeId @org.maproulette.controllers.api.DataController.getChallengeSummary(challengeId:Long, priority:String ?= "", includeByPriority:Boolean ?= false, virtualChallengeId:Long ?= 0) ### NoDocs ### GET /data/tag/metrics @org.maproulette.framework.controller.DataController.getTagMetrics()