Skip to content

Commit

Permalink
#13 Add ability to retrieve runs by the dataset ID
Browse files Browse the repository at this point in the history
Currently limits to the last 10 completed runs.
  • Loading branch information
chadlwilson committed Nov 5, 2021
1 parent f2cffc5 commit ff1c1ab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/main/kotlin/recce/server/api/DatasetRecRunController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package recce.server.api

import com.fasterxml.jackson.annotation.JsonProperty
import io.micronaut.core.annotation.Introspected
import io.micronaut.http.annotation.Body
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.Post
import io.micronaut.http.annotation.*
import io.micronaut.validation.Validated
import jakarta.inject.Inject
import mu.KotlinLogging
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import recce.server.dataset.DatasetRecRunner
import recce.server.recrun.DatasetMeta
Expand All @@ -33,6 +31,11 @@ class DatasetRecRunController(
return runRepository.findById(runId).map { CompletedRun(it) }
}

@Get
fun get(@QueryValue datasetId: String): Flux<CompletedRun> {
return runRepository.findTop10ByDatasetIdOrderByCompletedTimeDesc(datasetId).map { CompletedRun(it) }
}

@Post
fun create(@Body @Valid params: RunCreationParams): Mono<CompletedRun> {
logger.info { "Received request to create run for $params" }
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/recce/server/recrun/RecRunRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import io.micronaut.data.model.runtime.convert.AttributeConverter
import io.micronaut.data.r2dbc.annotation.R2dbcRepository
import io.micronaut.data.repository.reactive.ReactorCrudRepository
import jakarta.inject.Singleton
import reactor.core.publisher.Flux
import java.time.Instant
import javax.persistence.*

@R2dbcRepository(dialect = Dialect.POSTGRES)
interface RecRunRepository : ReactorCrudRepository<RecRun, Int>
interface RecRunRepository : ReactorCrudRepository<RecRun, Int> {
fun findTop10ByDatasetIdOrderByCompletedTimeDesc(datasetId: String): Flux<RecRun>
}

@Entity
@Table(name = "reconciliation_run")
Expand Down
14 changes: 14 additions & 0 deletions src/test/kotlin/recce/server/api/DatasetRecRunControllerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.junit.jupiter.api.Test
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import reactor.test.StepVerifier
import recce.server.dataset.DatasetRecRunner
Expand Down Expand Up @@ -50,6 +51,7 @@ private val service = mock<DatasetRecRunner> {
private val runRepository = mock<RecRunRepository> {
on { findById(testResults.id!!) } doReturn Mono.just(testResults)
on { findById(notFoundId) } doReturn Mono.empty()
on { findTop10ByDatasetIdOrderByCompletedTimeDesc(testDataset) } doReturn Flux.just(testResults, testResults)
}

internal class DatasetRecRunControllerTest {
Expand All @@ -64,6 +66,18 @@ internal class DatasetRecRunControllerTest {
.verifyComplete()
}

@Test
fun `can get runs by dataset id`() {
StepVerifier.create(controller.get(testDataset))
.assertNext {
assertThat(it).usingRecursiveComparison().isEqualTo(testResults)
}
.assertNext {
assertThat(it).usingRecursiveComparison().isEqualTo(testResults)
}
.verifyComplete()
}

@Test
fun `create should delegate to service`() {
StepVerifier.create(controller.create(DatasetRecRunController.RunCreationParams(eq(testDataset))))
Expand Down

0 comments on commit ff1c1ab

Please sign in to comment.