Add use cases for creating and destroying mute rules

This commit is contained in:
Karina Kwiatek 2022-07-24 11:01:22 +02:00
parent 7f9764a681
commit 8d650bb20f
2 changed files with 47 additions and 0 deletions

View file

@ -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

View file

@ -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