Newer
Older
# Copyright (c) 2010-2011, Diaspora Inc. This file is
MrZYX
a validé
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class LikesController < ApplicationController
include ApplicationHelper
before_action :authenticate_user!
Raphael Sofaer
a validé
Raphael Sofaer
a validé
MrZYX
a validé
def create
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid => e
MrZYX
a validé
if @like
respond_to do |format|
format.html { render :nothing => true, :status => 201 }
format.mobile { redirect_to post_path(@like.post_id) }
format.json { render :json => @like.as_api_response(:backbone), :status => 201 }
MrZYX
a validé
end
else
render text: I18n.t("likes.create.error"), status: 422
MrZYX
a validé
end
end
danielgrippi
a validé
def destroy
begin
@like = Like.find_by_id_and_author_id!(params[:id], current_user.person.id)
rescue ActiveRecord::RecordNotFound
render text: I18n.t("likes.destroy.error"), status: 404
return
end
current_user.retract(@like)
respond_to do |format|
format.json { render :nothing => true, :status => 204 }
danielgrippi
a validé
end
end
@likes = target.likes.includes(:author => :profile)
@people = @likes.map(&:author)
danielgrippi
a validé
respond_to do |format|
format.all { render :layout => false }
format.json { render :json => @likes.as_api_response(:backbone) }
def target
@target ||= if params[:post_id]
current_user.find_visible_shareable_by_id(Post, params[:post_id]) || raise(ActiveRecord::RecordNotFound.new)
Comment.find(params[:comment_id]).tap do |comment|
raise(ActiveRecord::RecordNotFound.new) unless current_user.find_visible_shareable_by_id(Post, comment.commentable_id)
end
danielgrippi
a validé
end
end