Skip to content
Snippets Groups Projects
Commit f9d7708e authored by Giovanne Marcelo's avatar Giovanne Marcelo
Browse files

Merge branch 'master' of gitlab.c3sl.ufpr.br:portalmec/portalmec into rspec

parents c8f987fe c82ce065
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment