fix(connector): id not being fetched from database after insert

This commit is contained in:
Anthony Berg 2024-05-02 17:59:40 +01:00
parent 2efc105ef2
commit c615149624
3 changed files with 21 additions and 23 deletions

View File

@ -4,7 +4,6 @@ import io.anthonyberg.connector.shared.database.ActionResultDatabase
import io.anthonyberg.connector.shared.database.DriverFactory
import io.anthonyberg.connector.shared.database.TestDatabase
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
/**
* Database transactions for testing procedures
@ -35,15 +34,11 @@ class TestTransaction (driverFactory: DriverFactory) {
* Tells the database that the test has ended
*
* @param id ID of the Test
*
* @return The final time for when the test ended
*/
fun endTest(id: Int): Instant {
fun endTest(id: Int) {
val currentTime = Clock.System.now()
testDb.endTest(testId = id.toLong(), endUTC = currentTime.toString())
return currentTime
}
/**
@ -72,10 +67,8 @@ class TestTransaction (driverFactory: DriverFactory) {
* Tells the database that the test has ended and adds the final state
*
* @param id ID of the ActionResult
*
* @return The time for when the test for the specific action finished
*/
fun finishAction(id: Int, endState: String): Instant {
fun finishAction(id: Int, endState: String) {
val currentTime = Clock.System.now()
actionResultDb.finishResult(
@ -83,7 +76,5 @@ class TestTransaction (driverFactory: DriverFactory) {
endState = endState,
endUTC = currentTime.toString()
)
return currentTime
}
}

View File

@ -15,14 +15,18 @@ internal class ActionResultDatabase (driverFactory: DriverFactory) {
initState: String,
startUTC: String
): Long {
dbQuery.startResult(
testId = testId,
actionId = actionId,
initState = initState,
startUTC = startUTC
)
val id = dbQuery.transactionWithResult {
dbQuery.startResult(
testId = testId,
actionId = actionId,
initState = initState,
startUTC = startUTC
)
return dbQuery.lastInsertedRowId().executeAsOne()
dbQuery.lastInsertedRowId().executeAsOne()
}
return id
}
/**

View File

@ -10,12 +10,15 @@ internal class TestDatabase (driverFactory: DriverFactory) {
* @return ID of the Test created
*/
internal fun startTest(procedureId: Long, startUTC: String) : Long {
dbQuery.startTest(
procedureId = procedureId,
startUTC = startUTC,
)
val id = dbQuery.transactionWithResult {
dbQuery.startTest(
procedureId = procedureId,
startUTC = startUTC,
)
dbQuery.lastInsertedRowId().executeAsOne()
}
return dbQuery.lastInsertedRowId().executeAsOne()
return id
}
/**