mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 10:09:53 +01:00
Add use cases for creating and destroying reactions
This commit is contained in:
parent
c0d169367e
commit
3811f15bd7
2 changed files with 39 additions and 0 deletions
20
lib/use_case/reaction/create.rb
Normal file
20
lib/use_case/reaction/create.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module UseCase
|
||||
module Reaction
|
||||
class Create < UseCase::Base
|
||||
option :source_user, type: Types.Instance(::User)
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
19
lib/use_case/reaction/destroy.rb
Normal file
19
lib/use_case/reaction/destroy.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module UseCase
|
||||
module Reaction
|
||||
class Destroy < UseCase::Base
|
||||
option :source_user, type: Types.Instance(::User)
|
||||
option :target, type: Types.Instance(::Answer) | Types.Instance(::Comment)
|
||||
|
||||
def call
|
||||
source_user.unsmile target
|
||||
|
||||
{
|
||||
status: 204,
|
||||
resource: nil,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue