Skip to content

Commit ed3c01d

Browse files
committed
Merge branch 'release/v1.9.0'
2 parents aac6826 + 3d7fa74 commit ed3c01d

File tree

9 files changed

+60
-40
lines changed

9 files changed

+60
-40
lines changed

backend/build.gradle.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group = "com.techprd"
6-
version = "1.7.0"
6+
version = "1.9.0"
77

88
repositories {
99
mavenCentral()
@@ -19,11 +19,11 @@ kotlin {
1919
js {
2020
nodejs {
2121
dependencies {
22-
implementation(npm("body-parser", "1.19.0"))
23-
implementation(npm("cookie-parser", "1.4.3"))
24-
implementation(npm("ejs", "2.5.6"))
25-
implementation(npm("express", "4.17.1"))
26-
implementation(npm("materialize-css", "1.0.0-rc.2"))
22+
implementation(npm("body-parser", "1.20.2"))
23+
implementation(npm("cookie-parser", "1.4.6"))
24+
implementation(npm("ejs", "3.1.9"))
25+
implementation(npm("express", "4.18.2"))
26+
implementation(npm("materialize-css", "1.0.0"))
2727
}
2828
}
2929
binaries.executable()

backend/src/main/kotlin/main.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ fun main() {
2424

2525
// view engine setup
2626
// TODO: find a better way to find the webapp views and js files
27-
app.set("views", path.join(__dirname, "../../../../../webapp/build/distributions"))
27+
app.set("views", path.join(__dirname, "../../../../../webapp/build/dist/js/productionExecutable"))
2828
app.set("view engine", "ejs")
29-
app.use(express.static(path.join(__dirname, "../../../../../webapp/build/distributions")))
29+
app.use(express.static(path.join(__dirname, "../../../../../webapp/build/dist/js/productionExecutable")))
3030

3131
http.createServer(app)
3232
app.listen(port) {

backend/src/main/kotlin/routes/route.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ fun router() {
2020
}
2121

2222
router.get("/api/tasks") { _, res ->
23-
res.send(db.values.toList())
23+
val values = JSON.stringify(db.values.map { it.toJson() })
24+
res.send(values)
2425
}
2526

2627
router.get("/api/task/:id") { req, res ->
2728
res.json(db[req.params.id])
2829
}
2930

3031
router.post("/api/task/:id") { req, res ->
31-
val task = JSON.parse<Task>(JSON.stringify(req.body))
32+
val task = Task.fromJson(req.body)
3233
db[task.id] = task
33-
res.json(task)
34+
res.send(task.toJson())
3435
}
3536

3637
return router

build.gradle.kts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
plugins {
2-
id("org.jetbrains.kotlin.js") version "1.7.0"
2+
id("org.jetbrains.kotlin.js") version "1.9.0"
33
}
44

55
group = "com.techprd"
6-
version = "1.7.0"
6+
version = "1.9.0"
77

88
repositories {
99
mavenCentral()
@@ -15,8 +15,3 @@ kotlin {
1515
nodejs()
1616
}
1717
}
18-
19-
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
20-
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().versions.webpackCli.version =
21-
"4.10.0"
22-
}

common/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group = "com.techprd"
6-
version = "1.7.0"
6+
version = "1.9.0"
77

88
repositories {
99
mavenCentral()

common/src/main/kotlin/model/Task.kt

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package model
22

3-
data class Task(val id: String, val text: String) {
4-
var isArchived = false
5-
var isDone = false
3+
import kotlin.js.Json
4+
import kotlin.js.json
5+
6+
data class Task(val id: String, val text: String, var isDone: Boolean = false, var isArchived: Boolean = false) {
67

78
fun markAsDone() {
89
isDone = true
@@ -11,4 +12,24 @@ data class Task(val id: String, val text: String) {
1112
fun archive() {
1213
isArchived = true
1314
}
15+
16+
fun toJson(): Json {
17+
return json(
18+
"id" to id,
19+
"text" to text,
20+
"isDone" to isDone,
21+
"isArchived" to isArchived
22+
)
23+
}
24+
25+
companion object {
26+
fun fromJson(it: Json): Task {
27+
return Task(
28+
id = it["id"] as String,
29+
text = it["text"] as String,
30+
isDone = it["isDone"] as Boolean,
31+
isArchived = it["isArchived"] as Boolean
32+
)
33+
}
34+
}
1435
}

webapp/build.gradle.kts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = "com.techprd"
8-
version = "1.7.0"
8+
version = "1.9.0"
99

1010
repositories {
1111
mavenCentral()
@@ -15,31 +15,34 @@ repositories {
1515

1616
dependencies {
1717
implementation(kotlin("stdlib-js"))
18-
implementation("org.jetbrains.kotlinx:kotlinx-html-js:0.7.5")
18+
implementation("org.jetbrains.kotlinx:kotlinx-html-js:0.9.1")
1919
implementation(project(":common"))
2020
}
2121

2222
kotlin {
2323
js {
2424
browser {
25-
webpackTask {
26-
cssSupport.enabled = true
27-
}
25+
webpackTask(Action {
26+
cssSupport {
27+
enabled.set(true)
28+
}
29+
})
2830

29-
runTask {
30-
cssSupport.enabled = true
31+
runTask(Action {
3132
devServer = KotlinWebpackConfig.DevServer(
32-
static = mutableListOf("$buildDir/distributions"),
33+
static = mutableListOf("$buildDir/processedResources/js/main"),
3334
proxy = hashMapOf("/api" to "http://localhost:3000")
3435
)
35-
}
36+
})
3637

37-
testTask {
38+
testTask(Action {
3839
useKarma {
3940
useChromeHeadless()
40-
webpackConfig.cssSupport.enabled = true
41+
webpackConfig.cssSupport {
42+
enabled.set(true)
43+
}
4144
}
42-
}
45+
})
4346
}
4447
binaries.executable()
4548
}

webapp/src/main/kotlin/services/Ajax.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package services
22

33
import model.Task
44
import org.w3c.xhr.*
5+
import kotlin.js.Json
56

67
class Ajax {
78

@@ -22,7 +23,7 @@ class Ajax {
2223
xhttp.send()
2324
}
2425

25-
fun post(url: String, task: Task, callback: (XMLHttpRequest) -> Unit) {
26+
fun post(url: String, task: Json, callback: (XMLHttpRequest) -> Unit) {
2627
xhttp.open(
2728
method = "POST",
2829
url = url,

webapp/src/main/kotlin/services/StorageService.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package services
22

33
import events.TodoEventEmitter
44
import model.Task
5+
import kotlin.js.Json
56

67
class StorageService(val eventEmitter: TodoEventEmitter) : LinkedHashMap<String, Task>() {
78

@@ -27,19 +28,17 @@ class StorageService(val eventEmitter: TodoEventEmitter) : LinkedHashMap<String,
2728

2829
fun getAll(callback: () -> Unit) {
2930
return Ajax().get("/api/tasks") {
30-
val tasks = JSON.parse<Array<Task>>(it.responseText)
31+
val tasks = JSON.parse<Array<Json>>(it.responseText)
3132
tasks.forEach {
32-
val task = Task(it.id, it.text)
33-
task.isArchived = it.isArchived
34-
task.isDone = it.isDone
33+
val task = Task.fromJson(it)
3534
this[task.id] = task
3635
}
3736
callback()
3837
}
3938
}
4039

4140
fun update(task: Task) {
42-
return Ajax().post("/api/task/${task.id}", task) {
41+
return Ajax().post("/api/task/${task.id}", task.toJson()) {
4342
console.log(it.response)
4443
}
4544
}

0 commit comments

Comments
 (0)