in app/controllers/ChannelTestsController.scala [229:270]
def setStatus(rawStatus: String) = authActions.write.async(circe.json[List[String]]) { request =>
run {
val testNames = request.body
logger.info(s"${request.user.email} is changing status to $rawStatus on: $testNames")
parseStatus(rawStatus) match {
case Some(models.Status.Archived) =>
// Special handling for archiving of tests, which are moved to another table
dynamoTests
.getRawTests(channel, testNames)
// write them to the archive table
.flatMap(dynamoArchivedTests.putAllRaw)
// now delete them from the main table
.flatMap(_ => dynamoTests.deleteTests(testNames, channel))
.map { _ =>
logger.info(s"Archived and deleted ${testNames.length} $channel tests")
Ok(rawStatus)
}
case Some(status) =>
dynamoTests.updateStatuses(testNames, channel, status)
.flatMap(_ => {
/**
* Fetch the full data for all the updated tests and then write audits.
* We use .forkDaemon here to avoid delaying the response to the client
* and instead run this task in the background.
*/
dynamoTests
.getTests(channel, testNames)
.flatMap(tests => dynamoTestsAudit.createAudits(tests, request.user.email))
.tapError(error => {
// Log the error but this will not affect the response to the client
ZIO.succeed(logger.error(s"Error creating audits after status changes: ${error.getMessage}", error))
})
.forkDaemon
})
.map(_ => Ok(status.toString))
case None => ZIO.succeed(BadRequest(s"Invalid status: $rawStatus"))
}
}
}