diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-03-09 15:49:25 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-03-09 15:49:25 -0500 |
commit | 9f8c1fce2c94c9fb040586740e28b3e83a3cc41f (patch) | |
tree | 0ad3b470b84c13187ff374c8f2a4d26383095c85 /src/guff/api | |
parent | 7417966101a0b0bbd0fefc8723482ae5a2010f19 (diff) | |
download | old-guff-9f8c1fce2c94c9fb040586740e28b3e83a3cc41f.tar.bz2 old-guff-9f8c1fce2c94c9fb040586740e28b3e83a3cc41f.zip |
add created_at sorting and use json for sort fields
Diffstat (limited to 'src/guff/api')
-rw-r--r-- | src/guff/api/methods.cr | 33 | ||||
-rw-r--r-- | src/guff/api/post.cr | 18 | ||||
-rw-r--r-- | src/guff/api/util.cr | 8 |
3 files changed, 44 insertions, 15 deletions
diff --git a/src/guff/api/methods.cr b/src/guff/api/methods.cr index 6c38eb3..9b35596 100644 --- a/src/guff/api/methods.cr +++ b/src/guff/api/methods.cr @@ -15,20 +15,38 @@ module Guff required: false, }, - "year": { - text: "Year filter", + "posted_year": { + text: "Post date year filter", type: :int, required: false, }, - "month": { - text: "Month filter", + "posted_month": { + text: "Post date month filter", type: :int, required: false, }, - "day": { - text: "Day filter", + "posted_day": { + text: "Post date day filter", + type: :int, + required: false, + }, + + "created_year": { + text: "Creation date year filter", + type: :int, + required: false, + }, + + "created_month": { + text: "Creation date month filter", + type: :int, + required: false, + }, + + "created_day": { + text: "Creation date day filter", type: :int, required: false, }, @@ -48,7 +66,7 @@ module Guff "sort": { text: "Sort order of results", - type: :sort, + type: :json, required: false, }, @@ -340,7 +358,6 @@ module Guff slug: /^[a-z0-9\.-]+$/, int: /^\d+$/, int_list: /^\d+(?:,\d+)*$/, - sort: /^[a-z0-9_]+,(?:asc|desc)$/, state: /^(?:draft|posted|deleted)$/, # FIXME: lock these down more diff --git a/src/guff/api/post.cr b/src/guff/api/post.cr index 499e7c0..f856d5b 100644 --- a/src/guff/api/post.cr +++ b/src/guff/api/post.cr @@ -4,12 +4,15 @@ module Guff module API module PostAPI GET_POSTS_FILTERS = { - q: "q", - year: "year", - month: "month", - day: "day", - slug: "slug", - state: "state", + q: "q", + posted_year: "posted_year", + posted_month: "posted_month", + posted_day: "posted_day", + created_year: "created_year", + created_month: "created_month", + created_day: "created_day", + slug: "slug", + state: "state", } private def do_post_get_posts( @@ -26,8 +29,9 @@ module Guff @models.post.get_posts( site_id: get_site(context), filters: filters, - tags: get_posts_tags(args["tags"]), + tags: get_posts_tags(args["tags"]?), page: args.has_key?("page") ? args["page"].to_i : 1, + sort: get_posts_sort(args["sort"]?), ) end diff --git a/src/guff/api/util.cr b/src/guff/api/util.cr index 525f098..72e7e5c 100644 --- a/src/guff/api/util.cr +++ b/src/guff/api/util.cr @@ -26,6 +26,14 @@ module Guff [] of Array(String) end end + + private def get_posts_sort( + s : String? + ) : Array(Hash(String, String))? + if s && s.size > 0 + Array(Hash(String, String)).from_json(s) + end + end end end end |