diff --git a/app/controllers/concerns/sociable_controller.rb b/app/controllers/concerns/sociable_controller.rb index 5f8f1e0921ceb1cee0258084012d4804648b69e9..2bdc8081e9de9b2103bedbadb027aae56c92ceda 100644 --- a/app/controllers/concerns/sociable_controller.rb +++ b/app/controllers/concerns/sociable_controller.rb @@ -6,26 +6,18 @@ module SociableController VIEWABLE_METHODS = [:show] included do - before_action :authenticate_user!, only: [:like, :unlike] - before_action :authorize_sociable!, only: [:like, :unlike] + before_action :authenticate_user!, only: [:like] + before_action :authorize_sociable!, only: [:like] before_action :view_object!, only: VIEWABLE_METHODS end - # POST /v1/learning_objects/1/like - # POST /v1/learning_objects/1/like.json + # PUT /v1/learning_objects/1/like + # PUT /v1/learning_objects/1/like.json def like if !sociable.liked? current_user sociable.like current_user render json: {count: sociable.likes.count}, status: :created - else - render status: :forbidden - end - end - - # DELETE /v1/learning_objects/1/unlike - # DELETE /v1/learning_objects/1/unlike.json - def unlike - if sociable.liked? current_user + elsif sociable.liked? current_user sociable.dislike current_user render json: {count: sociable.likes.count}, status: :ok else diff --git a/app/policies/sociable_policy.rb b/app/policies/sociable_policy.rb index a0b54bcc5e9c986fdddf5e0fb970509b30892357..392f3793932a1e92ce3fbd0acd62598b1046f7e7 100644 --- a/app/policies/sociable_policy.rb +++ b/app/policies/sociable_policy.rb @@ -4,10 +4,6 @@ module SociablePolicy record if user_exists? end - def unlike? - record if user_exists? - end - def liked? record if user_exists? end diff --git a/config/routes.rb b/config/routes.rb index ca60c9e1f8af743950e78af5539c08c242e33b88..222f2bd8e6727c844215ee0955020bda88f694a4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,8 +39,7 @@ Rails.application.routes.draw do concern :sociable do member do - post 'like', as: :like, action: :like - delete 'like', as: :unlike, action: :unlike + put 'like', as: :like, action: :like end end