aboutsummaryrefslogtreecommitdiff
path: root/src/guff/api/post.cr
diff options
context:
space:
mode:
Diffstat (limited to 'src/guff/api/post.cr')
-rw-r--r--src/guff/api/post.cr80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/guff/api/post.cr b/src/guff/api/post.cr
new file mode 100644
index 0000000..0bc6377
--- /dev/null
+++ b/src/guff/api/post.cr
@@ -0,0 +1,80 @@
+require "json"
+
+module Guff
+ module API
+ module PostAPI
+ private def do_post_get_posts(
+ context : HTTP::Server::Context,
+ args : Hash(String, String)
+ )
+ @models.post.get_posts(
+ site_id: get_site(context),
+ q: args["q"]? || "",
+ tags: get_posts_tags(args["tags"]),
+ page: args.has_key?("page") ? args["page"].to_i : 1,
+ ).to_json
+ end
+
+ private def do_post_add_post(
+ context : HTTP::Server::Context,
+ args : Hash(String, String)
+ )
+ post_id = @models.post.add_post(
+ site_id: get_site(context),
+ slug: args["slug"],
+ name: args["name"],
+ body: args["body"],
+ tags: get_tags(args["tags"]?),
+ )
+
+ # return json
+ { 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)
+ )
+ @models.post.remove_posts(
+ site_id: get_site(context),
+ post_ids: args["post_ids"].split(',').map { |post_id|
+ post_id.to_s.to_i
+ },
+ )
+
+ { ok: true }.to_json
+ end
+
+ private def do_post_set_tags(
+ context : HTTP::Server::Context,
+ args : Hash(String, String)
+ )
+ @models.post.set_tags(
+ site_id: get_site(context),
+ post_id: (args["post_id"] as String).to_i,
+ tags: get_tags(args["tags"]?),
+ )
+
+ { ok: true}.to_json
+ end
+ end
+ end
+end