Skip to content

Commit

Permalink
chore: use insertOne instead updateOne
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomoaccursi committed Apr 5, 2023
1 parent 8418826 commit cca5e50
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/kotlin/infrastructure/database/DatabaseManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import application.presenter.database.model.TimeSeriesMedicalTechnologyUsageMeta
import application.presenter.database.model.TimeSeriesPatientMedicalData
import application.presenter.database.model.TimeSeriesPatientMedicalDataMetadata
import application.presenter.database.model.TimeSeriesProcessStateEvent
import application.presenter.database.model.TimeSeriesProcessStateEventMetadata
import application.presenter.database.model.TimeSeriesProcessStepEvent
import application.presenter.database.model.TimeSeriesProcessStepEventMetadata
import application.presenter.database.model.toPatientMedicalData
import com.mongodb.MongoException
import com.mongodb.client.MongoCollection
Expand All @@ -36,7 +38,6 @@ import org.litote.kmongo.getCollection
import org.litote.kmongo.gt
import org.litote.kmongo.lte
import org.litote.kmongo.ne
import org.litote.kmongo.updateOne
import java.time.Instant

/**
Expand Down Expand Up @@ -150,7 +151,8 @@ class DatabaseManager(
state: ProcessData.ProcessState
): Boolean =
this.processStateEventCollection.safeMongoDbWrite(defaultResult = false) {
updateOne(SurgicalProcess::id eq processId).wasAcknowledged()
insertOne(TimeSeriesProcessStateEvent(dateTime, TimeSeriesProcessStateEventMetadata(processId), state))
.wasAcknowledged()
}

override fun updateSurgicalProcessStep(
Expand All @@ -159,7 +161,8 @@ class DatabaseManager(
step: ProcessData.ProcessStep
): Boolean =
this.processStepEventCollection.safeMongoDbWrite(defaultResult = false) {
updateOne(SurgicalProcess::id eq processId).wasAcknowledged()
insertOne(TimeSeriesProcessStepEvent(dateTime, TimeSeriesProcessStepEventMetadata(processId), step))
.wasAcknowledged()
}

private fun <T, R> MongoCollection<T>.safeMongoDbWrite(defaultResult: R, operation: MongoCollection<T>.() -> R): R =
Expand Down

0 comments on commit cca5e50

Please sign in to comment.