retrospring/lib/use_case/answer/unpin.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
537 B
Ruby
Raw Normal View History

2023-02-07 08:36:29 +01:00
# frozen_string_literal: true
module UseCase
module Answer
class Unpin < UseCase::Base
option :user, type: Types.Instance(::User)
option :answer, type: Types.Instance(::Answer)
def call
2023-02-10 11:34:55 +01:00
authorize!(:unpin, user, answer)
2023-02-07 08:36:29 +01:00
check_pinned!
answer.pinned_at = nil
answer.save!
{
status: 200,
2023-02-07 22:06:35 +01:00
resource: nil,
2023-02-07 08:36:29 +01:00
}
end
private
def check_pinned!
raise ::Errors::BadRequest if answer.pinned_at.nil?
end
end
end
end