From 05c8e00f6745f0c422e633fc8cf658be39fd8973 Mon Sep 17 00:00:00 2001 From: James Dunwoody Date: Tue, 1 Apr 2014 20:07:32 +1100 Subject: [PATCH] Created bounties and leaderboard controllers Api --- app/controllers/api/bounties_controller.rb | 13 +++++++++++++ app/controllers/api/leaderboard_controller.rb | 13 +++++++++++++ app/decorators/bounty_decorator.rb | 2 +- config/routes.rb | 2 ++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/controllers/api/bounties_controller.rb create mode 100644 app/controllers/api/leaderboard_controller.rb diff --git a/app/controllers/api/bounties_controller.rb b/app/controllers/api/bounties_controller.rb new file mode 100644 index 00000000..f9fea973 --- /dev/null +++ b/app/controllers/api/bounties_controller.rb @@ -0,0 +1,13 @@ +module Api + class BountiesController < ApplicationController + + respond_to :json + + def index + respond_with do |format| + format.json { render json: Bounty.unclaimed.order(:created_at).decorate } + end + end + + end +end diff --git a/app/controllers/api/leaderboard_controller.rb b/app/controllers/api/leaderboard_controller.rb new file mode 100644 index 00000000..aa747029 --- /dev/null +++ b/app/controllers/api/leaderboard_controller.rb @@ -0,0 +1,13 @@ +module Api + class LeaderboardController < ApplicationController + + respond_to :json + + def index + respond_with do |format| + format.json { render json: Queries::RunningLeaderboard.new.query.decorate } + end + end + + end +end diff --git a/app/decorators/bounty_decorator.rb b/app/decorators/bounty_decorator.rb index e6c1b6cf..369ae0f2 100644 --- a/app/decorators/bounty_decorator.rb +++ b/app/decorators/bounty_decorator.rb @@ -12,6 +12,6 @@ def created_at private def better_time time_field - object.public_send(time_field).strftime("%m/%d/%y %H:%M") + object.public_send(time_field).strftime("%m/%d/%y %H:%M") if object.send(time_field) end end diff --git a/config/routes.rb b/config/routes.rb index 2e655ef1..08cd8a08 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,6 +21,8 @@ end resources :events, only: [ :create ] + resources :leaderboard, only: [ :index ] + resources :bounties, only: [ :index ] namespace :adapters do resources :github, only: [ :create ]