diff --git a/modules/app-server/app/src/main/kotlin/app/server/app/AppModule.kt b/modules/app-server/app/src/main/kotlin/app/server/app/AppModule.kt index 23e819c7..1aa58b45 100644 --- a/modules/app-server/app/src/main/kotlin/app/server/app/AppModule.kt +++ b/modules/app-server/app/src/main/kotlin/app/server/app/AppModule.kt @@ -12,7 +12,8 @@ fun Application.module() { configureRouting( projectService = projectService, moduleService = moduleService, - environmentService = environmentService + environmentService = environmentService, + scriptService = scriptService ) configureSerialization() } \ No newline at end of file diff --git a/modules/app-server/app/src/main/kotlin/app/server/app/Dependencies.kt b/modules/app-server/app/src/main/kotlin/app/server/app/Dependencies.kt index 39a87328..7950623f 100644 --- a/modules/app-server/app/src/main/kotlin/app/server/app/Dependencies.kt +++ b/modules/app-server/app/src/main/kotlin/app/server/app/Dependencies.kt @@ -4,11 +4,13 @@ import dao.environment.EnvironmentDao import dao.module.ModuleDao import dao.project.ProjectDao import dao.project.ProjectHierarchyDao +import dao.script.ScriptDao import environment.EnvironmentService import module.ModuleService import org.jooq.SQLDialect import org.jooq.impl.DSL import project.ProjectService +import script.ScriptService import java.sql.DriverManager val dslContext = DSL.using( @@ -26,4 +28,7 @@ val moduleDao = ModuleDao(dslContext) val moduleService = ModuleService(moduleDao) val environmentDao = EnvironmentDao(dslContext) -val environmentService = EnvironmentService(environmentDao) \ No newline at end of file +val environmentService = EnvironmentService(environmentDao) + +val scriptDao = ScriptDao(dslContext) +val scriptService = ScriptService(scriptDao) \ No newline at end of file diff --git a/modules/app-server/dao/src/main/kotlin/dao/script/ScriptDao.kt b/modules/app-server/dao/src/main/kotlin/dao/script/ScriptDao.kt index c966b10d..75835e23 100644 --- a/modules/app-server/dao/src/main/kotlin/dao/script/ScriptDao.kt +++ b/modules/app-server/dao/src/main/kotlin/dao/script/ScriptDao.kt @@ -5,9 +5,10 @@ import org.jooq.DSLContext import org.jooq.impl.DSL.`val` import script.Script import script.ScriptCreationRequest +import script.ScriptDaoInterface -class ScriptDao(val dslContext: DSLContext) { - fun insert(data: ScriptCreationRequest): Script = +class ScriptDao(val dslContext: DSLContext): ScriptDaoInterface { + override fun insert(data: ScriptCreationRequest): Script = dslContext.insertInto(DM_SCRIPT, DM_SCRIPT.NAME, DM_SCRIPT.CHECKSUM, DM_SCRIPT.CONTENT) .values( `val`(data.name), @@ -16,13 +17,13 @@ class ScriptDao(val dslContext: DSLContext) { ).returningResult(DM_SCRIPT.CHECKSUM, DM_SCRIPT.NAME, DM_SCRIPT.CONTENT) .fetchSingleInto(Script::class.java) - fun delete(id: String) { + override fun delete(checksum: String) { dslContext.delete(DM_SCRIPT) - .where(DM_SCRIPT.CHECKSUM.eq(id)) + .where(DM_SCRIPT.CHECKSUM.eq(checksum)) .execute() } - fun findOneById(id: String): Script? = - dslContext.fetchOne(DM_SCRIPT, DM_SCRIPT.CHECKSUM.eq(id)) + override fun findOneByChecksum(checksum: String): Script? = + dslContext.fetchOne(DM_SCRIPT, DM_SCRIPT.CHECKSUM.eq(checksum)) ?.into(Script::class.java) } \ No newline at end of file diff --git a/modules/app-server/dao/src/test/kotlin/dao/script/ScriptDaoTest.kt b/modules/app-server/dao/src/test/kotlin/dao/script/ScriptDaoTest.kt index 8c3f8fe0..d74a9a5d 100644 --- a/modules/app-server/dao/src/test/kotlin/dao/script/ScriptDaoTest.kt +++ b/modules/app-server/dao/src/test/kotlin/dao/script/ScriptDaoTest.kt @@ -80,7 +80,7 @@ class ScriptDaoTest : AbstractDaoTest() { val checksum = UUID.randomUUID().toString() // When - val loadedScript = scriptDao.findOneById(checksum) + val loadedScript = scriptDao.findOneByChecksum(checksum) // Then expectThat(loadedScript).isNull() @@ -93,7 +93,7 @@ class ScriptDaoTest : AbstractDaoTest() { val insertedChecksum = scriptDao.insert(script).checksum // When - val loadedScript = scriptDao.findOneById(insertedChecksum) + val loadedScript = scriptDao.findOneByChecksum(insertedChecksum) // Then expectThat(loadedScript).isNotNull().and { @@ -116,7 +116,7 @@ class ScriptDaoTest : AbstractDaoTest() { scriptDao.delete(randomChecksum) // Then - expectThat(scriptDao.findOneById(insertedChecksum)).isNotNull() + expectThat(scriptDao.findOneByChecksum(insertedChecksum)).isNotNull() } @Test @@ -131,8 +131,8 @@ class ScriptDaoTest : AbstractDaoTest() { scriptDao.delete(insertedChecksum1) // Then - expectThat(scriptDao.findOneById(insertedChecksum1)).isNull() - expectThat(scriptDao.findOneById(insertedChecksum2)).isNotNull() + expectThat(scriptDao.findOneByChecksum(insertedChecksum1)).isNull() + expectThat(scriptDao.findOneByChecksum(insertedChecksum2)).isNotNull() } } } \ No newline at end of file diff --git a/modules/app-server/domain/src/main/kotlin/script/ScriptDaoInterface.kt b/modules/app-server/domain/src/main/kotlin/script/ScriptDaoInterface.kt new file mode 100644 index 00000000..8e436a7b --- /dev/null +++ b/modules/app-server/domain/src/main/kotlin/script/ScriptDaoInterface.kt @@ -0,0 +1,7 @@ +package script + +interface ScriptDaoInterface { + fun insert(data: ScriptCreationRequest): Script + fun delete(checksum: String) + fun findOneByChecksum(checksum: String): Script? +} \ No newline at end of file diff --git a/modules/app-server/domain/src/main/kotlin/script/ScriptService.kt b/modules/app-server/domain/src/main/kotlin/script/ScriptService.kt new file mode 100644 index 00000000..78558456 --- /dev/null +++ b/modules/app-server/domain/src/main/kotlin/script/ScriptService.kt @@ -0,0 +1,13 @@ +package script + +class ScriptService( + private val scriptDao: ScriptDaoInterface +) { + fun insert(data: ScriptCreationRequest): Script = + scriptDao.insert(data) + + fun delete(checksum: String) = scriptDao.delete(checksum) + + fun findOneByChecksum(checksum: String): Script? = + scriptDao.findOneByChecksum(checksum) +} \ No newline at end of file diff --git a/modules/app-server/rest/src/main/kotlin/rest/Application.kt b/modules/app-server/rest/src/main/kotlin/rest/Application.kt index d33b7854..25ee204a 100644 --- a/modules/app-server/rest/src/main/kotlin/rest/Application.kt +++ b/modules/app-server/rest/src/main/kotlin/rest/Application.kt @@ -8,33 +8,38 @@ import io.ktor.server.routing.* import module.ModuleService import project.ProjectService import rest.v1.route.routeV1 +import script.ScriptService fun main(args: Array): Unit = io.ktor.server.netty.EngineMain.main(args) fun Application.module( projectService: ProjectService, moduleService: ModuleService, - environmentService: EnvironmentService + environmentService: EnvironmentService, + scriptService: ScriptService ) { configureSerialization() configureRouting( projectService = projectService, moduleService = moduleService, - environmentService = environmentService + environmentService = environmentService, + scriptService = scriptService ) } fun Application.configureRouting( projectService: ProjectService, moduleService: ModuleService, - environmentService: EnvironmentService + environmentService: EnvironmentService, + scriptService: ScriptService ) { routing { route("/api") { routeV1( projectService = projectService, moduleService = moduleService, - environmentService = environmentService + environmentService = environmentService, + scriptService = scriptService ) } } diff --git a/modules/app-server/rest/src/main/kotlin/rest/v1/route/RouteV1.kt b/modules/app-server/rest/src/main/kotlin/rest/v1/route/RouteV1.kt index 87061c7d..8e2b83b7 100644 --- a/modules/app-server/rest/src/main/kotlin/rest/v1/route/RouteV1.kt +++ b/modules/app-server/rest/src/main/kotlin/rest/v1/route/RouteV1.kt @@ -7,15 +7,19 @@ import project.ProjectService import rest.v1.route.environment.environmentV1Routes import rest.v1.route.module.moduleV1Routes import rest.v1.route.project.projectV1Routes +import rest.v1.route.script.scriptV1Routes +import script.ScriptService fun Route.routeV1( projectService: ProjectService, moduleService: ModuleService, - environmentService: EnvironmentService + environmentService: EnvironmentService, + scriptService: ScriptService ) { route("/v1") { projectV1Routes(projectService) moduleV1Routes(moduleService) environmentV1Routes(environmentService) + scriptV1Routes(scriptService) } } \ No newline at end of file diff --git a/modules/app-server/rest/src/main/kotlin/rest/v1/route/script/ScriptDto.kt b/modules/app-server/rest/src/main/kotlin/rest/v1/route/script/ScriptDto.kt new file mode 100644 index 00000000..fe338c67 --- /dev/null +++ b/modules/app-server/rest/src/main/kotlin/rest/v1/route/script/ScriptDto.kt @@ -0,0 +1,16 @@ +package rest.v1.route.script + +import script.Script + +@kotlinx.serialization.Serializable +data class ScriptDtoV1( + val name: String, + val checksum: String, + val content: String +) + +fun Script.toDtoV1() = ScriptDtoV1( + name = this.name, + checksum = this.checksum, + content = this.checksum +) \ No newline at end of file diff --git a/modules/app-server/rest/src/main/kotlin/rest/v1/route/script/ScriptRoutesV1.kt b/modules/app-server/rest/src/main/kotlin/rest/v1/route/script/ScriptRoutesV1.kt new file mode 100644 index 00000000..1c4059cc --- /dev/null +++ b/modules/app-server/rest/src/main/kotlin/rest/v1/route/script/ScriptRoutesV1.kt @@ -0,0 +1,16 @@ +package rest.v1.route.script + +import io.ktor.server.application.* +import io.ktor.server.response.* +import io.ktor.server.routing.* +import script.ScriptService + +internal const val scriptId = "scriptId" + +internal fun ApplicationCall.scriptId() = this.parameters[scriptId] + +internal fun Route.scriptV1Routes(scriptService: ScriptService) { + get("/scripts/{$scriptId}") { + call.respondNullable(call.scriptId()?.let{ scriptService.findOneByChecksum(it) }?.toDtoV1()) + } +} \ No newline at end of file