retrospring/lib/use_case/reaction/create.rb
Andreas Nedbal cc7fa787e8 Pass IDs to Reaction usecases instead of user instances
For some wild reason this locally sometimes causes coercion errors in the user instance check, restarting fixes it (temporarily?) so letting the UseCase resolve users is a cleaner solution here.
2024-03-19 22:45:19 +01:00

26 lines
575 B
Ruby

# frozen_string_literal: true
module UseCase
module Reaction
class Create < UseCase::Base
option :source_user_id, type: Types::Coercible::Integer
option :target, type: Types.Instance(::Answer) | Types.Instance(::Comment)
option :content, type: Types::Coercible::String, optional: true
def call
reaction = source_user.smile target
{
status: 201,
resource: reaction,
}
end
private
def source_user
@source_user ||= ::User.find(source_user_id)
end
end
end
end