From 8d650bb20faa74a410d1635d462533d51b4763de Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 24 Jul 2022 11:01:22 +0200 Subject: [PATCH] Add use cases for creating and destroying mute rules --- lib/use_case/mute_rule/create.rb | 25 +++++++++++++++++++++++++ lib/use_case/mute_rule/destroy.rb | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 lib/use_case/mute_rule/create.rb create mode 100644 lib/use_case/mute_rule/destroy.rb diff --git a/lib/use_case/mute_rule/create.rb b/lib/use_case/mute_rule/create.rb new file mode 100644 index 00000000..980d1081 --- /dev/null +++ b/lib/use_case/mute_rule/create.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require "use_case/base" +require "errors" + +module UseCase + module MuteRule + class Create < UseCase::Base + option :user, type: Types.Instance(::User) + option :phrase, type: Types::Coercible::String + + def call + rule = MuteRule.create( + user:, + muted_phrase: phrase + ) + + { + status: 201, + resource: rule, + } + end + end + end +end diff --git a/lib/use_case/mute_rule/destroy.rb b/lib/use_case/mute_rule/destroy.rb new file mode 100644 index 00000000..841234c6 --- /dev/null +++ b/lib/use_case/mute_rule/destroy.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require "use_case/base" +require "errors" + +module UseCase + module MuteRule + class Destroy < UseCase::Base + option :user, type: Types.Instance(::User) + option :rule, Types.Instance(::MuteRule) + + def call + rule.destroy! + + { + status: 204, + resource: nil + } + end + end + end +end