();
+
+ viewObjects.put("templateName", "articleForm.ftl");
+
+ viewObjects.put("article", articleDbService.readOne(id));
+
+ return modelAndView(viewObjects, "layout.ftl");
+ }
+ });
+
+ post(new Route("/article/update/:id") {
+ @Override
+ public Object handle(Request request, Response response) {
+ Integer id = Integer.parseInt(request.queryParams("article-id"));
+ String title = request.queryParams("article-title");
+ String summary = request.queryParams("article-summary");
+ String content = request.queryParams("article-content");
+
+ articleDbService.update(id, title, summary, content);
+
+ response.status(200);
+ response.redirect("/");
+ return "";
+ }
+ });
+
+ get(new Route("/article/delete/:id") {
+ @Override
+ public Object handle(Request request, Response response) {
+ Integer id = Integer.parseInt(request.params(":id"));
+
+ articleDbService.delete(id);
+
+ response.status(200);
+ response.redirect("/");
+ return "";
+ }
+ });
}
}
\ No newline at end of file
diff --git a/src/main/resources/spark/template/freemarker/articleForm.ftl b/src/main/resources/spark/template/freemarker/articleForm.ftl
new file mode 100644
index 0000000..557eff0
--- /dev/null
+++ b/src/main/resources/spark/template/freemarker/articleForm.ftl
@@ -0,0 +1,23 @@
+
+
+
+
Content
+
+
value='Update'<#else>value='Publish'#if> class="btn btn-primary" form='article-create-form' />
+
\ No newline at end of file
diff --git a/src/main/resources/spark/template/freemarker/articleList.ftl b/src/main/resources/spark/template/freemarker/articleList.ftl
new file mode 100644
index 0000000..129e3e5
--- /dev/null
+++ b/src/main/resources/spark/template/freemarker/articleList.ftl
@@ -0,0 +1,14 @@
+<#if hasNoArticles??>
+
+
${hasNoArticles}
+
+<#else>
+
+ <#list articles as article>
+
${article.getTitle()}
+ ${article.getCreatedAt()}
+ ${article.getSummaryLink()}
+ ${article.getEditLink()} | ${article.getDeleteLink()}
+ #list>
+
+#if>
\ No newline at end of file
diff --git a/src/main/resources/spark/template/freemarker/articleRead.ftl b/src/main/resources/spark/template/freemarker/articleRead.ftl
new file mode 100644
index 0000000..cae3938
--- /dev/null
+++ b/src/main/resources/spark/template/freemarker/articleRead.ftl
@@ -0,0 +1,6 @@
+
+
${article.getTitle()}
+ ${article.getCreatedAt()}
+ ${article.getEditLink()} | ${article.getDeleteLink()}
+ ${article.getContent()}
+
\ No newline at end of file
diff --git a/src/main/resources/spark/template/freemarker/layout.ftl b/src/main/resources/spark/template/freemarker/layout.ftl
new file mode 100644
index 0000000..199cc1c
--- /dev/null
+++ b/src/main/resources/spark/template/freemarker/layout.ftl
@@ -0,0 +1,36 @@
+
+
+ Spark Blog
+
+
+
+
+
+
+
+
+
+ <#include "${templateName}">
+
+
+
+
+
+