From cc215f6a414fa01048dc3726cf0329596140b89d Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 21 Dec 2016 03:34:45 -0600 Subject: [PATCH] Add more artist commentary API endpoints. * GET /posts/1/artist_commentary.json * GET /artist_commentaries/1.json --- app/controllers/artist_commentaries_controller.rb | 14 +++++++++++++- config/routes.rb | 6 +++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/controllers/artist_commentaries_controller.rb b/app/controllers/artist_commentaries_controller.rb index 51d338f3f..a5a7e53bd 100644 --- a/app/controllers/artist_commentaries_controller.rb +++ b/app/controllers/artist_commentaries_controller.rb @@ -1,6 +1,6 @@ class ArtistCommentariesController < ApplicationController respond_to :html, :xml, :json, :js - before_filter :member_only, :except => [:index] + before_filter :member_only, :except => [:index, :show] def index @commentaries = ArtistCommentary.search(params[:search]).order("artist_commentaries.id desc").paginate(params[:page], :limit => params[:limit]) @@ -11,6 +11,18 @@ class ArtistCommentariesController < ApplicationController end end + def show + if params[:id] + @commentary = ArtistCommentary.find(params[:id]) + else + @commentary = ArtistCommentary.find_by_post_id!(params[:post_id]) + end + + respond_with(@commentary) do |format| + format.html { redirect_to post_path(@commentary.post) } + end + end + def create_or_update @artist_commentary = ArtistCommentary.find_by_post_id(params[:artist_commentary][:post_id]) diff --git a/config/routes.rb b/config/routes.rb index e4b2805dd..8874ad087 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -193,6 +193,10 @@ Rails.application.routes.draw do resources :pool_versions, :only => [:index] resources :posts do resources :events, :only => [:index], :controller => "post_events" + resource :artist_commentary, :only => [:index, :show] do + collection { put :create_or_update } + member { put :revert } + end resources :votes, :controller => "post_votes", :only => [:create, :destroy] collection do get :home @@ -216,7 +220,7 @@ Rails.application.routes.draw do get :search end end - resources :artist_commentaries do + resources :artist_commentaries, :only => [:index, :show] do collection do put :create_or_update get :search