This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<div id="app"> | |
<input type="text" @keyup.enter="addTodo"> | |
<ul> | |
<li v-for="todo in todos"> | |
{{todo.text}} | |
</li> | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>VueJS / Kotlin ToDo App</title> | |
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
<script src="https://unpkg.com/vue"></script> | |
</head> | |
<body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package codemwnci | |
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | |
import com.github.kittinunf.fuel.Fuel | |
import org.junit.* | |
import kotlin.test.* | |
import spark.Spark | |
class UsageTest { | |
companion object { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
put(":id") { req, res -> | |
val update = jacksonObjectMapper().readTree(req.body()) | |
if (!update.has("text") || !update.has("done")) badRequest("text and done required in JSON body string") | |
val rowsUpdated = using(sessionOf(HikariCP.dataSource())) { session -> | |
session.run(queryOf("update todo set text=?, done=? where id=?", | |
update.get("text").asText(), update.get("done").asBoolean(), req.params("id").toLong()) | |
.asUpdate) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
delete(":id") { req, res -> | |
val rowsDeleted = using(sessionOf(HikariCP.dataSource())) { session -> | |
session.run(queryOf("delete from todo where id=?", req.params("id").toLong()).asUpdate) | |
} | |
if (rowsDeleted == 1) "ok" | |
else serverError("something went wrong") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>codemwnci</groupId> | |
<artifactId>KotlinToDoApp</artifactId> | |
<version>1.0-SNAPSHOT</version> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get("") { req, res -> | |
val todos: List<Todo> = using(sessionOf(HikariCP.dataSource())) { session -> | |
session.run( queryOf("select id, text, done, created_at from todo").map(toTodo).asList ) | |
} | |
jacksonObjectMapper().writeValueAsString(todos) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get(":id") { req, res -> | |
jacksonObjectMapper().writeValueAsString( getTodo(req.params("id").toLong()) ) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
setupDB() | |
port(9000) | |
staticFileLocation("/public/") | |
path("/todo/") { | |
data class Todo(val id: Long, val text: String, val done: Boolean, val createdAt: LocalDateTime) | |
val toTodo: (Row) -> Todo = { row -> Todo(row.long(1), row.string(2), row.boolean(3), row.localDateTime(4))} |
NewerOlder