From 46418b2237f86dc7b41c8c2a3dd5725634dceffe Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Tue, 8 Mar 2016 13:07:57 -0500 Subject: add date filters --- src/guff/api/post.cr | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/guff/api/post.cr') 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, ) -- cgit v1.2.3