2022-05-28 11:03:36 +02:00
|
|
|
class FollowsController < ApplicationController
|
|
|
|
|
before_action :authenticate_user!, only: [:create, :destroy]
|
2024-05-03 18:11:07 +02:00
|
|
|
before_action :check_tenant_subscription, only: [:create, :destroy]
|
2022-05-28 11:03:36 +02:00
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
unless user_signed_in?
|
|
|
|
|
render json: { }
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
follow = Follow.find_by(follow_params)
|
|
|
|
|
render json: follow
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
follow = Follow.new(follow_params)
|
|
|
|
|
|
|
|
|
|
if follow.save
|
|
|
|
|
render json: {
|
|
|
|
|
id: follow.id
|
|
|
|
|
}, status: :created
|
|
|
|
|
else
|
|
|
|
|
render json: {
|
2022-06-05 11:40:43 +02:00
|
|
|
error: follow.errors.full_messages
|
2022-05-28 11:03:36 +02:00
|
|
|
}, status: :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
follow = Follow.find_by(follow_params)
|
|
|
|
|
id = follow.id
|
|
|
|
|
|
|
|
|
|
return if follow.nil?
|
|
|
|
|
|
|
|
|
|
if follow.destroy
|
|
|
|
|
render json: {
|
|
|
|
|
id: id,
|
|
|
|
|
}, status: :accepted
|
|
|
|
|
else
|
|
|
|
|
render json: {
|
2022-06-05 11:40:43 +02:00
|
|
|
error: follow.errors.full_messages
|
2022-05-28 11:03:36 +02:00
|
|
|
}, status: :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def follow_params
|
|
|
|
|
{
|
|
|
|
|
post_id: params[:post_id],
|
|
|
|
|
user_id: current_user.id,
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|