@@ -8,6 +8,9 @@ package org.maproulette.framework.repository
8
8
import org .slf4j .LoggerFactory
9
9
10
10
import anorm .ToParameterValue
11
+ import anorm ._
12
+ import anorm .SqlParser .scalar
13
+
11
14
import org .maproulette .cache .CacheManager
12
15
import anorm ._ , postgresql ._
13
16
import javax .inject .{Inject , Singleton }
@@ -201,13 +204,29 @@ class TaskBundleRepository @Inject() (
201
204
)
202
205
.executeUpdate()
203
206
207
+ // Define the fallback value
208
+ val fallbackStatus : Int = 0
209
+
204
210
// Retrieve the status of the primary task
205
- val primaryTaskStatus = SQL (
211
+ val primaryTaskStatus : Int = SQL (
206
212
""" SELECT status FROM tasks WHERE id = {primaryTaskId}"""
207
213
).on(
208
214
" primaryTaskId" -> primaryTaskId
209
215
)
210
- .as(SqlParser .scalar[Int ].single)
216
+ .as(scalar[Int ].singleOpt)
217
+ .getOrElse(fallbackStatus)
218
+
219
+ // Define the fallback value for review status
220
+ val fallbackReviewStatus : Int = 0
221
+
222
+ // Retrieve the review status of the primary task
223
+ val primaryTaskReviewStatus : Int = SQL (
224
+ """ SELECT review_status FROM task_review WHERE id = {primaryTaskId}"""
225
+ ).on(
226
+ " primaryTaskId" -> primaryTaskId
227
+ )
228
+ .as(scalar[Int ].singleOpt)
229
+ .getOrElse(fallbackReviewStatus)
211
230
212
231
val lockedTasks = this .withListLocking(user, Some (TaskType ())) { () =>
213
232
this .taskDAL.retrieveListById(- 1 , 0 )(tasksToAdd)
@@ -222,14 +241,17 @@ class TaskBundleRepository @Inject() (
222
241
SQL (
223
242
""" UPDATE tasks
224
243
SET status = {primaryTaskStatus}
225
- WHERE bundle_id = {bundleId }
244
+ WHERE id = {taskId }
226
245
"""
227
246
).on(
228
247
" primaryTaskStatus" -> primaryTaskStatus,
229
- " bundleId " -> bundleId
248
+ " taskId " -> task.id
230
249
)
231
250
.executeUpdate()
232
251
252
+ SQL """ INSERT INTO task_review (task_id, review_status)
253
+ VALUES ( ${task.id}, ${primaryTaskReviewStatus}) """ .executeUpdate()
254
+
233
255
this .cacheManager.withOptionCaching { () =>
234
256
Some (
235
257
task.copy(
0 commit comments