Skip to content
Extraits de code Groupes Projets
likes_controller.rb 1,12 ko
Newer Older
  • Learn to ignore specific revisions
  • danielgrippi's avatar
    danielgrippi a validé
    #   Copyright (c) 2010-2011, Diaspora Inc.  This file is
    
    #   licensed under the Affero General Public License version 3 or later.  See
    #   the COPYRIGHT file.
    
    class LikesController < ApplicationController
      include ApplicationHelper
    
      before_action :authenticate_user!
    
    danielgrippi's avatar
    danielgrippi a validé
      respond_to :html,
                 :mobile,
                 :json
    
        like = like_service.create(params[:post_id])
      rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
        render text: I18n.t("likes.create.error"), status: 422
      else
        respond_to do |format|
    
          format.html { head :created }
    
          format.mobile { redirect_to post_path(like.post_id) }
          format.json { render json: like.as_api_response(:backbone), status: 201 }
    
        if like_service.destroy(params[:id])
    
          head :no_content
    
          render text: I18n.t("likes.destroy.error"), status: 404
    
    Raphael Sofaer's avatar
    Raphael Sofaer a validé
    
      def index
    
        render json: like_service.find_for_post(params[:post_id])
          .includes(author: :profile)
          .as_api_response(:backbone)
    
    Raphael Sofaer's avatar
    Raphael Sofaer a validé
      end
    
      def like_service
        @like_service ||= LikeService.new(current_user)