Skip to content

Commit

Permalink
feat: Add ScriptExecution first route
Browse files Browse the repository at this point in the history
  • Loading branch information
asolovieff committed Dec 12, 2023
1 parent 2413aab commit ab1767e
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ fun Application.module() {
moduleService = moduleService,
environmentService = environmentService,
scriptService = scriptService,
batchExecutionService = batchExecutionService
batchExecutionService = batchExecutionService,
scriptExecutionService = scriptExecutionService
)
configureSerialization()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import dao.module.ModuleDao
import dao.project.ProjectDao
import dao.project.ProjectHierarchyDao
import dao.script.ScriptDao
import dao.script.execution.ScriptExecutionDao
import environment.EnvironmentService
import execution.batch.BatchExecutionService
import module.ModuleService
import org.jooq.SQLDialect
import org.jooq.impl.DSL
import project.ProjectService
import script.ScriptService
import script.execution.ScriptExecutionService
import java.sql.DriverManager

val dslContext = DSL.using(
Expand All @@ -36,4 +38,7 @@ val scriptDao = ScriptDao(dslContext)
val scriptService = ScriptService(scriptDao)

val batchExecutionDao = BatchExecutionDao(dslContext)
val batchExecutionService = BatchExecutionService(batchExecutionDao)
val batchExecutionService = BatchExecutionService(batchExecutionDao)

val scriptExecutionDao = ScriptExecutionDao(dslContext)
val scriptExecutionService = ScriptExecutionService(scriptExecutionDao)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package script.execution

import java.util.*

class ScriptExecutionService(
private val scriptExecutionDao: ScriptExecutionDaoInterface
) {
fun insert(data: ScriptExecutionCreationRequest): ScriptExecution =
scriptExecutionDao.insert(data)

fun updateScriptExecutionStartData(
scriptExecutionId: UUID,
executionStartData: ScriptExecutionStartUpdateRequest
): ScriptExecution? =
scriptExecutionDao.updateScriptExecutionStartData(scriptExecutionId, executionStartData)

fun updateScriptExecutionEndData(
scriptExecutionId: UUID,
executionEndData: ScriptExecutionEndUpdateRequest
): ScriptExecution? =
scriptExecutionDao.updateScriptExecutionEndData(scriptExecutionId, executionEndData)

fun delete(id: UUID) = scriptExecutionDao.delete(id)

fun findOneById(id: UUID): ScriptExecution? = scriptExecutionDao.findOneById(id)
}
13 changes: 9 additions & 4 deletions modules/app-server/rest/src/main/kotlin/rest/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import module.ModuleService
import project.ProjectService
import rest.v1.route.routeV1
import script.ScriptService
import script.execution.ScriptExecutionService

fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)

Expand All @@ -18,15 +19,17 @@ fun Application.module(
moduleService: ModuleService,
environmentService: EnvironmentService,
scriptService: ScriptService,
batchExecutionService: BatchExecutionService
batchExecutionService: BatchExecutionService,
scriptExecutionService: ScriptExecutionService
) {
configureSerialization()
configureRouting(
projectService = projectService,
moduleService = moduleService,
environmentService = environmentService,
scriptService = scriptService,
batchExecutionService = batchExecutionService
batchExecutionService = batchExecutionService,
scriptExecutionService = scriptExecutionService
)
}

Expand All @@ -35,7 +38,8 @@ fun Application.configureRouting(
moduleService: ModuleService,
environmentService: EnvironmentService,
scriptService: ScriptService,
batchExecutionService: BatchExecutionService
batchExecutionService: BatchExecutionService,
scriptExecutionService: ScriptExecutionService
) {
routing {
route("/api") {
Expand All @@ -44,7 +48,8 @@ fun Application.configureRouting(
moduleService = moduleService,
environmentService = environmentService,
scriptService = scriptService,
batchExecutionService = batchExecutionService
batchExecutionService = batchExecutionService,
scriptExecutionService = scriptExecutionService
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ import rest.v1.route.environment.environmentV1Routes
import rest.v1.route.execution.batch.batchExecutionV1Routes
import rest.v1.route.module.moduleV1Routes
import rest.v1.route.project.projectV1Routes
import rest.v1.route.script.execution.scriptExecutionV1Routes
import rest.v1.route.script.scriptV1Routes
import script.ScriptService
import script.execution.ScriptExecutionService

fun Route.routeV1(
projectService: ProjectService,
moduleService: ModuleService,
environmentService: EnvironmentService,
scriptService: ScriptService,
batchExecutionService: BatchExecutionService
batchExecutionService: BatchExecutionService,
scriptExecutionService: ScriptExecutionService
) {
route("/v1") {
projectV1Routes(projectService)
moduleV1Routes(moduleService)
environmentV1Routes(environmentService)
scriptV1Routes(scriptService)
batchExecutionV1Routes(batchExecutionService)
scriptExecutionV1Routes(scriptExecutionService)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package rest.v1.route.script.execution

import execution.Status
import kotlinx.serialization.Serializable
import rest.OffsetDateTimeSerializer
import rest.UUIDSerializer
import rest.v1.route.execution.StatusDtoV1
import rest.v1.route.execution.toDtoV1
import script.execution.ScriptExecution
import java.time.OffsetDateTime
import java.util.UUID

@Serializable
data class ScriptExecutionDtoV1(
@Serializable(with = UUIDSerializer::class)
val id: UUID,
@Serializable(with = OffsetDateTimeSerializer::class)
val startDate: OffsetDateTime? = null,
@Serializable(with = OffsetDateTimeSerializer::class)
val endDate: OffsetDateTime? = null,
val durationInMs: Int? = null,
val executionOrderIndex: Int,
val output: String? = null,
val status: StatusDtoV1? = null
)

fun ScriptExecution.toDtoV1() = ScriptExecutionDtoV1(
id = this.id,
startDate = this.startDate,
endDate = this.endDate,
durationInMs = this.durationInMs,
executionOrderIndex = this.executionOrderIndex,
output = this.output,
status = this.status?.toDtoV1()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package rest.v1.route.script.execution

import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import script.execution.ScriptExecutionService
import java.util.UUID

internal const val scriptExecutionId = "scriptExecutionId"

internal fun ApplicationCall.scriptExecutionId() = UUID.fromString(this.parameters[scriptExecutionId])

internal fun Route.scriptExecutionV1Routes(scriptExecutionService: ScriptExecutionService) {
get("/scriptExecutions/{$scriptExecutionId}") {
call.respondNullable(call.scriptExecutionId()?.let { scriptExecutionService.findOneById(it)?.toDtoV1() })
}
}

0 comments on commit ab1767e

Please sign in to comment.