fix reaction deletion bug and clean up controller
Turns out the strange error where it would delete the wrong reaction occurred because I forgot to pass the emoji name to the query, which resulted in the database deleting the first reaction it found. Also, this removes the unused set_reaction callback and includes the Authorization module for the status reactions controller.
This commit is contained in:
parent
3588c37413
commit
df673abeea
2 changed files with 5 additions and 9 deletions
|
@ -1,11 +1,11 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Api::V1::Statuses::ReactionsController < Api::BaseController
|
class Api::V1::Statuses::ReactionsController < Api::BaseController
|
||||||
|
include Authorization
|
||||||
|
|
||||||
before_action -> { doorkeeper_authorize! :write, :'write:favourites' }
|
before_action -> { doorkeeper_authorize! :write, :'write:favourites' }
|
||||||
before_action :require_user!
|
before_action :require_user!
|
||||||
|
|
||||||
before_action :set_status
|
before_action :set_status
|
||||||
before_action :set_reaction, except: :update
|
|
||||||
|
|
||||||
def update
|
def update
|
||||||
ReactService.new.call(current_account, @status, params[:id])
|
ReactService.new.call(current_account, @status, params[:id])
|
||||||
|
@ -13,16 +13,12 @@ class Api::V1::Statuses::ReactionsController < Api::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
UnreactService.new.call(current_account, @status)
|
UnreactService.new.call(current_account, @status, params[:id])
|
||||||
render_empty
|
render_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_reaction
|
|
||||||
@reaction = @status.status_reactions.where(account: current_account).find_by!(name: params[:id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_status
|
def set_status
|
||||||
@status = Status.find(params[:status_id])
|
@status = Status.find(params[:status_id])
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
class UnreactService < BaseService
|
class UnreactService < BaseService
|
||||||
include Payloadable
|
include Payloadable
|
||||||
|
|
||||||
def call(account, status)
|
def call(account, status, name)
|
||||||
reaction = StatusReaction.find_by(account: account, status: status)
|
reaction = StatusReaction.find_by(account: account, status: status, name: name)
|
||||||
return if reaction.nil?
|
return if reaction.nil?
|
||||||
|
|
||||||
reaction.destroy!
|
reaction.destroy!
|
||||||
|
|
Loading…
Reference in a new issue