Allow filtering by solved or unsolved

This commit is contained in:
David Taylor 2017-02-27 18:19:21 +00:00
parent 73e4909615
commit 2e4a7bc482
1 changed files with 21 additions and 0 deletions

View File

@ -337,6 +337,27 @@ SQL
end end
end end
require_dependency 'topic_query'
TopicQuery.add_custom_filter(:solved) do |results, topic_query|
if topic_query.options[:solved] == 'true'
results = results.where("topics.id IN (
SELECT tc.topic_id
FROM topic_custom_fields tc
WHERE tc.name = 'accepted_answer_post_id' AND
tc.value IS NOT NULL
)")
elsif topic_query.options[:solved] == 'false'
results = results.where("topics.id NOT IN (
SELECT tc.topic_id
FROM topic_custom_fields tc
WHERE tc.name = 'accepted_answer_post_id' AND
tc.value IS NOT NULL
)")
end
results
end
require_dependency 'topic_list_item_serializer' require_dependency 'topic_list_item_serializer'
class ::TopicListItemSerializer class ::TopicListItemSerializer