2023-01-29 12:00:47 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module UseCase
|
|
|
|
module Answer
|
|
|
|
class Pin < UseCase::Base
|
|
|
|
option :user, type: Types.Instance(::User)
|
|
|
|
option :answer, type: Types.Instance(::Answer)
|
|
|
|
|
|
|
|
def call
|
2023-02-10 02:34:55 -08:00
|
|
|
authorize!(:pin, user, answer)
|
2023-02-07 13:55:39 -08:00
|
|
|
check_unpinned!
|
2023-01-29 12:00:47 -08:00
|
|
|
|
|
|
|
answer.pinned_at = Time.now.utc
|
|
|
|
answer.save!
|
|
|
|
|
|
|
|
{
|
|
|
|
status: 200,
|
2023-02-07 13:06:35 -08:00
|
|
|
resource: answer,
|
2023-01-29 12:00:47 -08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-02-07 13:55:39 -08:00
|
|
|
def check_unpinned!
|
|
|
|
raise ::Errors::BadRequest if answer.pinned_at.present?
|
|
|
|
end
|
2023-01-29 12:00:47 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|