aboutsummaryrefslogtreecommitdiff
path: root/src/guff/handlers
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-03-10 00:22:20 -0500
committerPaul Duncan <pabs@pablotron.org>2016-03-10 00:22:20 -0500
commitf2691054f86ad45e90eb8473569def04ae3d95cd (patch)
treea347ba1972c4797f54988e4a3bdeae5dfa0583d1 /src/guff/handlers
parent9f8c1fce2c94c9fb040586740e28b3e83a3cc41f (diff)
downloadold-guff-f2691054f86ad45e90eb8473569def04ae3d95cd.tar.bz2
old-guff-f2691054f86ad45e90eb8473569def04ae3d95cd.zip
add blog test page
Diffstat (limited to 'src/guff/handlers')
-rw-r--r--src/guff/handlers/test.cr44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/guff/handlers/test.cr b/src/guff/handlers/test.cr
index f373630..f3ba35c 100644
--- a/src/guff/handlers/test.cr
+++ b/src/guff/handlers/test.cr
@@ -1,12 +1,50 @@
require "../handler"
+require "../views/html/test"
class Guff::Handlers::TestHandler < Guff::Handler
def call(context : HTTP::Server::Context)
- if ((context.request.path || "").match(/^\/test\//))
- context.response.content_type = "text/html"
- context.response.puts "test"
+ case (context.request.path || "") as String
+ when /^\/test\/?$/
+ draw_page(context)
+ when /^\/test\/set_state$/
+ set_state(context)
+ when /^\/test\/add_post$/
+ add_post(context)
else
call_next(context)
end
end
+
+ private def draw_page(context)
+ TestHTMLView.run(@models, context)
+ end
+
+ private def add_post(context)
+ params = HTTP::Params.parse(context.request.body as String)
+
+ @models.post.add_post(
+ name: params["name"].to_s,
+ slug: params["slug"].to_s,
+ body: params["body"].to_s,
+ tags: ["_blog"] + (params["tags"] || "").to_s.split(" "),
+ )
+
+ redirect(context)
+ end
+
+ private def set_state(context)
+ params = HTTP::Params.parse(context.request.body as String)
+
+ @models.post.update_post(
+ post_id: params["post_id"].to_i,
+ state: params["state"].to_s,
+ )
+
+ redirect(context)
+ end
+
+ private def redirect(context)
+ context.response.status_code = 302
+ context.response.headers["location"] = "/test"
+ end
end