From 7ac12f70691b9e6820aa9b5f7f2009a631b7d0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lise=20Rubio?= Date: Wed, 7 Aug 2024 16:31:24 +0200 Subject: [PATCH] :sparkles: Display most recent batch execution from backend --- .../dao/execution/batch/BatchExecutionDao.kt | 7 ++ .../execution/batch/BatchExecutionDaoTest.kt | 67 +++++++++++++++++-- .../batch/BatchExecutionDaoInterface.kt | 1 + .../execution/batch/BatchExecutionService.kt | 2 + .../execution/batch/BatchExecutionRoutesV1.kt | 4 ++ .../molecules/M_cardDashboard.svelte | 10 +-- .../ui/src/lib/domain/execution/Execution.ts | 11 ++- .../ui/src/lib/services/ExecutionService.ts | 8 +-- 8 files changed, 90 insertions(+), 20 deletions(-) diff --git a/modules/app-server/dao/src/main/kotlin/dao/execution/batch/BatchExecutionDao.kt b/modules/app-server/dao/src/main/kotlin/dao/execution/batch/BatchExecutionDao.kt index 2e20d085..b4d769aa 100644 --- a/modules/app-server/dao/src/main/kotlin/dao/execution/batch/BatchExecutionDao.kt +++ b/modules/app-server/dao/src/main/kotlin/dao/execution/batch/BatchExecutionDao.kt @@ -75,6 +75,13 @@ class BatchExecutionDao(private val dslContext: DSLContext): BatchExecutionDaoIn .fetchInto(BatchExecutionListItem::class.java) } + override fun findMostRecentExecutions(): List { + return selectBatchExecutionListItemData() + .orderBy(DM_BATCH_EXECUTION.START_DATE.desc()) + .limit(4) + .fetchInto(BatchExecutionListItem::class.java) + } + private fun selectBatchExecutionListItemData() = dslContext .select( DM_BATCH_EXECUTION.ID, diff --git a/modules/app-server/dao/src/test/kotlin/dao/execution/batch/BatchExecutionDaoTest.kt b/modules/app-server/dao/src/test/kotlin/dao/execution/batch/BatchExecutionDaoTest.kt index cc7b118e..773cde28 100644 --- a/modules/app-server/dao/src/test/kotlin/dao/execution/batch/BatchExecutionDaoTest.kt +++ b/modules/app-server/dao/src/test/kotlin/dao/execution/batch/BatchExecutionDaoTest.kt @@ -10,6 +10,7 @@ import environment.Environment import execution.INITIAL_STATUS import execution.Status import execution.batch.BatchExecutionEndUpdateRequest +import execution.batch.BatchExecutionListItem import execution.batch.BatchExecutionSearchRequest import generated.domain.tables.pojos.DmBatchExecution import generated.domain.tables.references.DM_BATCH_EXECUTION @@ -19,10 +20,7 @@ import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import project.Project import strikt.api.expectThat -import strikt.assertions.isEqualTo -import strikt.assertions.isNotNull -import strikt.assertions.isNull -import strikt.assertions.size +import strikt.assertions.* import java.time.OffsetDateTime import java.time.ZoneOffset import java.util.* @@ -592,6 +590,67 @@ internal class BatchExecutionDaoTest : AbstractDaoTest() { } } + @Nested + inner class TestFindMostRecentExecutions { + @Test + fun `should return the 4 executions with the greatest start dates, ordered by start date`() { + // Given + val date = OffsetDateTime.of(2023, 5, 2, 14, 26, 0, 0, ZoneOffset.UTC) + batchExecutionDao.insert(buildBatchExecutionCreationRequest( + startDate = date.toInstant(), + fkModuleRef = module1.id, + fkEnvironmentRef = environment1.id + )) + val mostRecentExecutions = listOf( + batchExecutionDao.insert( + buildBatchExecutionCreationRequest( + startDate = date.plusDays(4).toInstant(), + fkModuleRef = module1.id, + fkEnvironmentRef = environment1.id + ) + ), + batchExecutionDao.insert( + buildBatchExecutionCreationRequest( + startDate = date.plusDays(3).toInstant(), + fkModuleRef = module1.id, + fkEnvironmentRef = environment1.id + ) + ), + batchExecutionDao.insert( + buildBatchExecutionCreationRequest( + startDate = date.plusDays(2).toInstant(), + fkModuleRef = module1.id, + fkEnvironmentRef = environment1.id + ) + ), + batchExecutionDao.insert( + buildBatchExecutionCreationRequest( + startDate = date.plusDays(1).toInstant(), + fkModuleRef = module1.id, + fkEnvironmentRef = environment1.id + ) + ) + ) + + // When + val loadedMostRecent = batchExecutionDao.findMostRecentExecutions() + + // Then + expectThat(loadedMostRecent).isEqualTo(mostRecentExecutions.map { BatchExecutionListItem( + id = it.id, + startDate = it.startDate, + endDate = it.endDate, + durationInMs = it.durationInMs, + origin = it.origin, + status = it.status, + type = it.type, + project = project1, + module = module1, + environment = environment1 + ) }) + } + } + private fun findOneDmBatchExecutionById(id: UUID?) = dslContext.select( DM_BATCH_EXECUTION.ID, diff --git a/modules/app-server/domain/src/main/kotlin/execution/batch/BatchExecutionDaoInterface.kt b/modules/app-server/domain/src/main/kotlin/execution/batch/BatchExecutionDaoInterface.kt index 123f22f3..f08a5ff5 100644 --- a/modules/app-server/domain/src/main/kotlin/execution/batch/BatchExecutionDaoInterface.kt +++ b/modules/app-server/domain/src/main/kotlin/execution/batch/BatchExecutionDaoInterface.kt @@ -15,4 +15,5 @@ interface BatchExecutionDaoInterface { fun delete(id: UUID) fun findOneById(id: UUID): BatchExecutionListItem? fun find(searchRequest: BatchExecutionSearchRequest): List + fun findMostRecentExecutions(): List } \ No newline at end of file diff --git a/modules/app-server/domain/src/main/kotlin/execution/batch/BatchExecutionService.kt b/modules/app-server/domain/src/main/kotlin/execution/batch/BatchExecutionService.kt index 5ccdc2fa..7e8ba112 100644 --- a/modules/app-server/domain/src/main/kotlin/execution/batch/BatchExecutionService.kt +++ b/modules/app-server/domain/src/main/kotlin/execution/batch/BatchExecutionService.kt @@ -45,4 +45,6 @@ class BatchExecutionService( fun find(searchRequest: BatchExecutionSearchRequest): List = batchExecutionDao.find(searchRequest) + + fun findMostRecentExecutions(): List = batchExecutionDao.findMostRecentExecutions() } \ No newline at end of file diff --git a/modules/app-server/rest/src/main/kotlin/rest/v1/route/execution/batch/BatchExecutionRoutesV1.kt b/modules/app-server/rest/src/main/kotlin/rest/v1/route/execution/batch/BatchExecutionRoutesV1.kt index 4490c02b..2bb34c24 100644 --- a/modules/app-server/rest/src/main/kotlin/rest/v1/route/execution/batch/BatchExecutionRoutesV1.kt +++ b/modules/app-server/rest/src/main/kotlin/rest/v1/route/execution/batch/BatchExecutionRoutesV1.kt @@ -32,5 +32,9 @@ internal fun Route.batchExecutionV1Routes(batchExecutionService: BatchExecutionS get("/{$batchExecutionId}/detail") { call.respondNullable(call.batchExecutionId()?.let { batchExecutionService.findOneDetailById(it)?.toDtoV1() }) } + + get ("/mostRecent") { + call.respond(batchExecutionService.findMostRecentExecutions().map { it.toDtoV1() }) + } } } \ No newline at end of file diff --git a/modules/ui/src/lib/components/molecules/M_cardDashboard.svelte b/modules/ui/src/lib/components/molecules/M_cardDashboard.svelte index 2324a782..9ba09b3c 100644 --- a/modules/ui/src/lib/components/molecules/M_cardDashboard.svelte +++ b/modules/ui/src/lib/components/molecules/M_cardDashboard.svelte @@ -55,7 +55,7 @@
-
+
@@ -64,7 +64,7 @@
-
Début d’execution : {execution.date}
+
Début d’execution : {execution.startDate}
Temps d’execution : {execution.duration}
Nombre de scripts : {execution.nbScriptsKO + execution.nbScriptsOK}
KO : {execution.nbScriptsKO}
@@ -73,9 +73,9 @@
- + + Accéder au détail +