From 3811f15bd7f0621a2376846b6190b2f0413fefcc Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 28 Oct 2023 17:16:03 +0200 Subject: [PATCH] Add use cases for creating and destroying reactions --- lib/use_case/reaction/create.rb | 20 ++++++++++++++++++++ lib/use_case/reaction/destroy.rb | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 lib/use_case/reaction/create.rb create mode 100644 lib/use_case/reaction/destroy.rb diff --git a/lib/use_case/reaction/create.rb b/lib/use_case/reaction/create.rb new file mode 100644 index 00000000..a126bba3 --- /dev/null +++ b/lib/use_case/reaction/create.rb @@ -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 diff --git a/lib/use_case/reaction/destroy.rb b/lib/use_case/reaction/destroy.rb new file mode 100644 index 00000000..52fe3b7a --- /dev/null +++ b/lib/use_case/reaction/destroy.rb @@ -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