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

41 lines
955 B
Ruby
Raw Normal View History

2019-07-02 08:10:25 +01:00
# frozen_string_literal: true
class Api::V1::Statuses::PinsController < Api::BaseController
include Authorization
before_action -> { doorkeeper_authorize! :write, :'write:accounts' }
before_action :require_user!
before_action :set_status
def create
2020-11-25 21:22:37 +00:00
pin = StatusPin.find_by(account: current_account, status: @status)
if pin.nil?
StatusPin.create!(account: current_account, status: @status)
render json: @status, serializer: REST::StatusPinnedSerializer
else
return render json: { error: 'Status is already pinned' }, status: 500
end
2019-07-02 08:10:25 +01:00
end
2020-11-15 18:48:32 +00:00
def show
2020-11-25 21:22:37 +00:00
render json: @status, serializer: REST::StatusPinnedSerializer
2020-11-15 18:48:32 +00:00
end
2019-07-02 08:10:25 +01:00
def destroy
pin = StatusPin.find_by(account: current_account, status: @status)
if pin
pin.destroy!
end
2020-11-25 21:22:37 +00:00
render json: @status, serializer: REST::StatusPinnedSerializer
2019-07-02 08:10:25 +01:00
end
private
def set_status
@status = Status.find(params[:status_id])
end
end