From 490464d7d07e94b6ee69bbbc4b290a2b0e3a0975 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Tue, 8 Mar 2016 04:38:03 -0500 Subject: add update_post --- src/guff/api-methods.cr | 55 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'src/guff/api-methods.cr') diff --git a/src/guff/api-methods.cr b/src/guff/api-methods.cr index 14c71c2..334be88 100644 --- a/src/guff/api-methods.cr +++ b/src/guff/api-methods.cr @@ -77,6 +77,41 @@ module Guff }, }, + "update_post": { + text: "Update existing post.", + args: { + "name": { + text: "Post title.", + type: :text, + required: false, + }, + + "slug": { + text: "Post slug.", + type: :slug, + required: false, + }, + + "body": { + text: "Post body.", + type: :text, + required: false, + }, + + "tags": { + text: "Post tags.", + type: :json, + required: false, + }, + + "posted": { + text: "Is this post posted?", + type: :bool, + required: false, + }, + }, + }, + "remove_posts": { text: "Remove existing posts.", @@ -353,7 +388,7 @@ module Guff site_id: get_site(context), slug: args["slug"], name: args["name"], - body: args["name"], + body: args["body"], tags: get_tags(args["tags"]?), ) @@ -361,6 +396,24 @@ module Guff { post_id: post_id }.to_json end + private def do_post_update_post( + context : HTTP::Server::Context, + args : Hash(String, String) + ) + post_id = @models.post.update_post( + site_id: get_site(context), + post_id: args["post_id"].to_i, + slug: args["slug"]?, + name: args["name"], + body: args["body"], + tags: args.has_key?("tags") ? get_tags(args["tags"]?) : nil, + posted: args["posted"]?, + ) + + # return json + { ok: true }.to_json + end + private def do_post_remove_posts( context : HTTP::Server::Context, args : Hash(String, String) -- cgit v1.2.3