From 2f2c892670eefb1f750c595fa6bb3188fce55e2f Mon Sep 17 00:00:00 2001 From: r888888888 Date: Fri, 7 Jun 2013 16:32:36 -0700 Subject: [PATCH] fixes #742, #590: add new counts controller api --- app/controllers/counts_controller.rb | 7 +++++++ app/views/counts/posts.json.erb | 1 + app/views/counts/posts.xml.erb | 6 ++++++ config/routes.rb | 5 +++++ 4 files changed, 19 insertions(+) create mode 100644 app/controllers/counts_controller.rb create mode 100644 app/views/counts/posts.json.erb create mode 100644 app/views/counts/posts.xml.erb diff --git a/app/controllers/counts_controller.rb b/app/controllers/counts_controller.rb new file mode 100644 index 000000000..9f5b16285 --- /dev/null +++ b/app/controllers/counts_controller.rb @@ -0,0 +1,7 @@ +class CountsController < ApplicationController + respond_to :xml, :json + + def posts + @count = Post.fast_count(params[:tags]) + end +end diff --git a/app/views/counts/posts.json.erb b/app/views/counts/posts.json.erb new file mode 100644 index 000000000..002fead90 --- /dev/null +++ b/app/views/counts/posts.json.erb @@ -0,0 +1 @@ +{"counts": {"posts": <%= @count %>}} \ No newline at end of file diff --git a/app/views/counts/posts.xml.erb b/app/views/counts/posts.xml.erb new file mode 100644 index 000000000..e89efa3a7 --- /dev/null +++ b/app/views/counts/posts.xml.erb @@ -0,0 +1,6 @@ + + + + <%= @count %> + + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6d43b60b6..8886f94b2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -81,6 +81,11 @@ Danbooru::Application.routes.draw do get :index_all end end + resources :counts do + collection do + get :posts + end + end resources :delayed_jobs, :only => [:index] resources :dmails do collection do