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.
This commit is contained in:
parent
b4cfc95c83
commit
cc7fa787e8
|
@ -19,7 +19,7 @@ class ReactionsController < ApplicationController
|
||||||
target = target_class.find(params[:id])
|
target = target_class.find(params[:id])
|
||||||
|
|
||||||
UseCase::Reaction::Create.call(
|
UseCase::Reaction::Create.call(
|
||||||
source_user: current_user,
|
source_user_id: current_user.id,
|
||||||
target:,
|
target:,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class ReactionsController < ApplicationController
|
||||||
target = target_class.find(params[:id])
|
target = target_class.find(params[:id])
|
||||||
|
|
||||||
UseCase::Reaction::Destroy.call(
|
UseCase::Reaction::Destroy.call(
|
||||||
source_user: current_user,
|
source_user_id: current_user.id,
|
||||||
target:,
|
target:,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
module UseCase
|
module UseCase
|
||||||
module Reaction
|
module Reaction
|
||||||
class Create < UseCase::Base
|
class Create < UseCase::Base
|
||||||
option :source_user, type: Types.Instance(::User)
|
option :source_user_id, type: Types::Coercible::Integer
|
||||||
option :target, type: Types.Instance(::Answer) | Types.Instance(::Comment)
|
option :target, type: Types.Instance(::Answer) | Types.Instance(::Comment)
|
||||||
option :content, type: Types::Coercible::String, optional: true
|
option :content, type: Types::Coercible::String, optional: true
|
||||||
|
|
||||||
|
@ -15,6 +15,12 @@ module UseCase
|
||||||
resource: reaction,
|
resource: reaction,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def source_user
|
||||||
|
@source_user ||= ::User.find(source_user_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
module UseCase
|
module UseCase
|
||||||
module Reaction
|
module Reaction
|
||||||
class Destroy < UseCase::Base
|
class Destroy < UseCase::Base
|
||||||
option :source_user, type: Types.Instance(::User)
|
option :source_user_id, type: Types::Coercible::Integer
|
||||||
option :target, type: Types.Instance(::Answer) | Types.Instance(::Comment)
|
option :target, type: Types.Instance(::Answer) | Types.Instance(::Comment)
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
@ -14,6 +14,12 @@ module UseCase
|
||||||
resource: nil,
|
resource: nil,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def source_user
|
||||||
|
@source_user ||= ::User.find(source_user_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue