Skip to content

Commit

Permalink
make bundling data more usefule
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Jan 7, 2025
1 parent 5dac797 commit a117905
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
42 changes: 24 additions & 18 deletions app/org/maproulette/controllers/api/TaskController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -378,20 +378,26 @@ class TaskController @Inject() (
def lockTaskBundleByIds(taskIds: List[Long]): Action[AnyContent] = Action.async {
implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val results = taskIds.map { taskId =>
this.dal.retrieveById(taskId) match {
case Some(task) =>
try {
this.dal.lockItem(user, task)
Some(taskId)
} catch {
case _: LockedException => None
}
case None => None
}
}.flatten
val (lockedTasks, failedTasks) = taskIds.foldLeft((List.empty[Task], List.empty[Long])) {
case ((locked, failed), taskId) =>
this.dal.retrieveById(taskId) match {
case Some(task) =>
try {
this.dal.lockItem(user, task)
(task :: locked, failed)
} catch {
case _: LockedException => (locked, taskId :: failed)
}
case None => (locked, failed)
}
}

Ok(Json.toJson(results))
if (failedTasks.nonEmpty) {
lockedTasks.foreach(task => this.dal.unlockItem(user, task))
Ok(Json.toJson(failedTasks, false))
} else {
Ok(Json.toJson(lockedTasks, true))
}
}
}

Expand All @@ -404,7 +410,7 @@ class TaskController @Inject() (
def unlockTaskBundleByIds(taskIds: List[Long]): Action[AnyContent] = Action.async {
implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val results = taskIds.map { taskId =>
val tasks = taskIds.flatMap { taskId =>
this.dal.retrieveById(taskId) match {
case Some(task) =>
try {
Expand All @@ -415,9 +421,9 @@ class TaskController @Inject() (
}
case None => None
}
}.flatten
}

Ok(Json.toJson(results))
Ok(Json.toJson(tasks))
}
}

Expand All @@ -430,7 +436,7 @@ class TaskController @Inject() (
def refreshTaskLocksByIds(taskIds: List[Long]): Action[AnyContent] = Action.async {
implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val results = taskIds.map { taskId =>
val result = taskIds.map { taskId =>
this.dal.retrieveById(taskId) match {
case Some(task) =>
try {
Expand All @@ -443,7 +449,7 @@ class TaskController @Inject() (
}
}.flatten

Ok(Json.toJson(results))
Ok(Json.toJson(result))
}
}

Expand Down
7 changes: 2 additions & 5 deletions conf/v2_route/task.api
Original file line number Diff line number Diff line change
Expand Up @@ -916,14 +916,13 @@ GET /tasks/box/:left/:bottom/:right/:top @org.maproulette.framework.c
# description: Success
###
GET /taskCluster @org.maproulette.framework.controller.TaskController.getTaskClusters(points:Int ?= 100)

###
# tags: [ Task ]
# summary: Locks a bundle of tasks
# description: Locks the specified tasks in the bundle.
# description: Attempts to lock a set of tasks. If successful, returns the tasks that were locked. If not successful, returns the tasks that were not locked.
# responses:
# '200':
# description: Success message
# description: List of tasks that were locked or list of tasks that were not locked. Boolean indicates if the tasks were locked.
# '401':
# description: The user is not authorized to make this request
# requestBody:
Expand All @@ -937,7 +936,6 @@ GET /taskCluster @org.maproulette.framework.c
# type: integer
###
POST /task/bundle/lock @org.maproulette.controllers.api.TaskController.lockTaskBundleByIds(taskIds:List[Long])

###
# tags: [ Task ]
# summary: Unlocks a bundle of tasks
Expand All @@ -958,7 +956,6 @@ POST /task/bundle/lock @org.maproulette.controllers.a
# type: integer
###
POST /task/bundle/unlock @org.maproulette.controllers.api.TaskController.unlockTaskBundleByIds(taskIds:List[Long])

###
# tags: [ Task ]
# summary: Refreshes locks on a bundle of tasks
Expand Down

0 comments on commit a117905

Please sign in to comment.