Skip to content

Commit

Permalink
✨ Display most recent batch execution from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysoun committed Aug 7, 2024
1 parent c8a6077 commit 7ac12f7
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class BatchExecutionDao(private val dslContext: DSLContext): BatchExecutionDaoIn
.fetchInto(BatchExecutionListItem::class.java)
}

override fun findMostRecentExecutions(): List<BatchExecutionListItem> {
return selectBatchExecutionListItemData()
.orderBy(DM_BATCH_EXECUTION.START_DATE.desc())
.limit(4)
.fetchInto(BatchExecutionListItem::class.java)
}

private fun selectBatchExecutionListItemData() = dslContext
.select(
DM_BATCH_EXECUTION.ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.*
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ interface BatchExecutionDaoInterface {
fun delete(id: UUID)
fun findOneById(id: UUID): BatchExecutionListItem?
fun find(searchRequest: BatchExecutionSearchRequest): List<BatchExecutionListItem>
fun findMostRecentExecutions(): List<BatchExecutionListItem>
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ class BatchExecutionService(

fun find(searchRequest: BatchExecutionSearchRequest): List<BatchExecutionListItem> =
batchExecutionDao.find(searchRequest)

fun findMostRecentExecutions(): List<BatchExecutionListItem> = batchExecutionDao.findMostRecentExecutions()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() })
}
}
}
10 changes: 5 additions & 5 deletions modules/ui/src/lib/components/molecules/M_cardDashboard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</div>

<div class="mCard-indicators-item cell shrink">
<div><A_indicator label="{execution.env.smallName}"></A_indicator></div>
<div><A_indicator label="{execution.environment.smallName}"></A_indicator></div>
</div>
</div>
<div class="mCard-favorite cell shrink grid-x align-middle">
Expand All @@ -64,7 +64,7 @@
</div>
</div>
<div class="mCard-content cell auto">
<div><span>Début d’execution :</span> {execution.date}</div>
<div><span>Début d’execution :</span> {execution.startDate}</div>
<div><span>Temps d’execution :</span> {execution.duration}</div>
<div><span>Nombre de scripts :</span> {execution.nbScriptsKO + execution.nbScriptsOK}</div>
<div><span>KO :</span> {execution.nbScriptsKO}</div>
Expand All @@ -73,9 +73,9 @@
<div class="mCard-progressBar cell shrink">
<M_progressBar status="{execution.status}" ghostMode="{ghostMode}"></M_progressBar>
</div>
<div class="mCard-link cell shrink">
Accéder au détails
</div>
<a href="/executions/{execution.id}" class="mCard-link cell shrink">
Accéder au détail
</a>
</div>

<style lang="scss">
Expand Down
11 changes: 5 additions & 6 deletions modules/ui/src/lib/domain/execution/Execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,23 @@ export class ScriptExecutionDetail {
export class ExecutionForDashboard extends Execution {
project: {id: string, name: string, smallName: string}
module: {id: string, name: string}
env: {id: string, name: string, smallName: string}
environment: {id: string, name: string, smallName: string}
nbScriptsKO: number
nbScriptsOK: number


constructor(id: string, date: Date, origin: ExecutionOrigin, type: ExecutionType, status: ExecutionStatus, duration: number, project: {
constructor(id: string, startDate: Date, endDate: Date, origin: ExecutionOrigin, type: ExecutionType, status: ExecutionStatus, duration: number, project: {
id: string;
name: string;
smallName: string
}, module: { id: string; name: string }, env: {
}, module: { id: string; name: string }, environment: {
id: string;
name: string;
smallName: string
}, nbScriptsKO: number, nbScriptsOK: number) {
super(id, date, origin, type, status, duration);
super(id, startDate, endDate, origin, type, status, duration);
this.project = project;
this.module = module;
this.env = env;
this.environment = environment;
this.nbScriptsKO = nbScriptsKO;
this.nbScriptsOK = nbScriptsOK;
}
Expand Down
8 changes: 3 additions & 5 deletions modules/ui/src/lib/services/ExecutionService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {Execution, ExecutionForDashboard} from "$lib/domain/execution/Execution";
import {ExecutionDetail} from "$lib/domain/execution/Execution";
import type {Execution} from "$lib/domain/execution/Execution";
import {ExecutionDetail, ExecutionForDashboard} from "$lib/domain/execution/Execution";
import {ExecutionMock} from "$lib/mocks/ExecutionMock";
import {ScriptEnvMatrix} from '$lib/domain/script/ScriptEnvMatrix';
import {Http} from '$lib/services/utils/HttpService';
Expand All @@ -14,9 +14,7 @@ export class ExecutionService {
}

public static async searchMostRecent(): Promise<ExecutionForDashboard[]> {
return new Promise((resolve) => {
resolve(ExecutionMock.executionsForDashboard);
});
return Http.getAsArray<ExecutionForDashboard>(`api/v1/batchExecutions/mostRecent`, ExecutionForDashboard);
}

public static async detailById(id: string): Promise<ExecutionDetail> {
Expand Down

0 comments on commit 7ac12f7

Please sign in to comment.