gab-social/app/controllers/api/v1/groups/pins_controller.rb

49 lines
1.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class Api::V1::Groups::PinsController < Api::BaseController
include Authorization
before_action -> { doorkeeper_authorize! :write, :'write:groups' }
before_action :require_user!
before_action :set_group
before_action :set_status
def create
authorize @group, :update?
2020-11-25 21:22:37 +00:00
pin = GroupPinnedStatus.find_by(group: @group, status: @status)
if pin.nil?
GroupPinnedStatus.create!(group: @group, status: @status)
render json: @status, serializer: REST::StatusGroupPinnedSerializer, group_id: @group.id
else
return render json: { error: 'Status is already pinned to group' }, status: 500
end
end
2020-11-15 18:48:32 +00:00
def show
2020-11-25 21:22:37 +00:00
render json: @status, serializer: REST::StatusGroupPinnedSerializer, group_id: @group.id
2020-11-15 18:48:32 +00:00
end
def destroy
authorize @group, :update?
pin = GroupPinnedStatus.find_by(group: @group, status: @status)
if pin
pin.destroy!
end
2020-11-25 21:22:37 +00:00
render json: @status, serializer: REST::StatusGroupPinnedSerializer, group_id: @group.id
end
private
def set_status
@status = Status.find(params[:statusId])
end
def set_group
@group = Group.find(params[:group_id])
end
end