diff options
Diffstat (limited to 'src/guff/api/post.cr')
-rw-r--r-- | src/guff/api/post.cr | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/guff/api/post.cr b/src/guff/api/post.cr index 7141530..55abd86 100644 --- a/src/guff/api/post.cr +++ b/src/guff/api/post.cr @@ -3,13 +3,27 @@ require "json" module Guff module API module PostAPI + GET_POSTS_FILTERS = { + q: "q", + year: "year", + month: "month", + day: "day", + } + private def do_post_get_posts( context : HTTP::Server::Context, args : Hash(String, String) ) + # build filters + filters = GET_POSTS_FILTERS.reduce({} of Symbol => String) do |r, k, s| + r[k] = args[s] if args.has_key?(s) + r + end + + # get and return posts @models.post.get_posts( site_id: get_site(context), - q: args["q"]? || "", + filters: filters, tags: get_posts_tags(args["tags"]), page: args.has_key?("page") ? args["page"].to_i : 1, ) |