diff --git a/api/src/main/kotlin/com/wbrawner/twigs/TransactionRoutes.kt b/api/src/main/kotlin/com/wbrawner/twigs/TransactionRoutes.kt index 0e381b7..d9e6c78 100644 --- a/api/src/main/kotlin/com/wbrawner/twigs/TransactionRoutes.kt +++ b/api/src/main/kotlin/com/wbrawner/twigs/TransactionRoutes.kt @@ -128,7 +128,7 @@ fun Application.transactionRoutes( } call.respond( transactionRepository.save( - Transaction( + transaction.copy( title = request.title ?: transaction.title, description = request.description ?: transaction.description, amount = request.amount ?: transaction.amount, diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 94b5570..64a137b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { implementation(project(":api")) implementation(project(":core")) implementation(project(":db")) + implementation(project(":web")) implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion") implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") implementation("io.ktor:ktor-server-core:$ktorVersion") diff --git a/app/src/main/kotlin/com/wbrawner/twigs/server/Application.kt b/app/src/main/kotlin/com/wbrawner/twigs/server/Application.kt index 727d7a3..66a0ca7 100644 --- a/app/src/main/kotlin/com/wbrawner/twigs/server/Application.kt +++ b/app/src/main/kotlin/com/wbrawner/twigs/server/Application.kt @@ -3,6 +3,7 @@ package com.wbrawner.twigs.server import com.wbrawner.twigs.* import com.wbrawner.twigs.db.* import com.wbrawner.twigs.storage.* +import com.wbrawner.twigs.web.webRoutes import com.zaxxer.hikari.HikariConfig import com.zaxxer.hikari.HikariDataSource import io.ktor.application.* @@ -110,6 +111,7 @@ fun Application.moduleWithDependencies( categoryRoutes(categoryRepository, permissionRepository) transactionRoutes(transactionRepository, permissionRepository) userRoutes(permissionRepository, sessionRepository, userRepository) + webRoutes() launch { val metadata = (metadataRepository.findAll().firstOrNull() ?: DatabaseMetadata()) var version = metadata.version diff --git a/settings.gradle.kts b/settings.gradle.kts index 4eb59e4..e00464a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,2 @@ rootProject.name = "twigs" -include("core", "api", "app") -include("storage") -include("db") +include("core", "api", "app", "storage", "db", "web") diff --git a/web/.gitignore b/web/.gitignore new file mode 100644 index 0000000..adc3828 --- /dev/null +++ b/web/.gitignore @@ -0,0 +1,2 @@ +build/ +src/main/resources/twigs/ \ No newline at end of file diff --git a/web/build.gradle.kts b/web/build.gradle.kts new file mode 100644 index 0000000..158a8a6 --- /dev/null +++ b/web/build.gradle.kts @@ -0,0 +1,17 @@ +plugins { + kotlin("jvm") + `java-library` +} + +val ktorVersion: String by rootProject.extra + +dependencies { + implementation(kotlin("stdlib")) + api("io.ktor:ktor-server-core:$ktorVersion") + testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") +} + +tasks.getByName("test") { + useJUnitPlatform() +} diff --git a/web/src/main/kotlin/com/wbrawner/twigs/web/WebRoutes.kt b/web/src/main/kotlin/com/wbrawner/twigs/web/WebRoutes.kt new file mode 100644 index 0000000..144d698 --- /dev/null +++ b/web/src/main/kotlin/com/wbrawner/twigs/web/WebRoutes.kt @@ -0,0 +1,24 @@ +package com.wbrawner.twigs.web + +import io.ktor.application.* +import io.ktor.http.content.* +import io.ktor.request.* +import io.ktor.response.* +import io.ktor.routing.* + +fun Application.webRoutes() { + routing { + static { + resources("twigs") + default("index.html") + } + intercept(ApplicationCallPipeline.Setup) { + if (!call.request.path().startsWith("/api") && !call.request.path().matches(Regex(".*\\.\\w+$"))) { + call.resolveResource("twigs/index.html")?.let { + call.respond(it) + return@intercept finish() + } + } + } + } +} \ No newline at end of file