Retrospring/lib/use_case/answer/unpin.rb

34 lines
623 B
Ruby
Raw Normal View History

2023-02-06 23:36:29 -08: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
check_ownership!
check_pinned!
answer.pinned_at = nil
answer.save!
{
status: 200,
resource: nil
}
end
private
def check_ownership!
raise ::Errors::NotAuthorized unless answer.user == user
end
def check_pinned!
raise ::Errors::BadRequest if answer.pinned_at.nil?
end
end
end
end