Merge pull request #559 from Retrospring/return-hashes-from-use-cases

This commit is contained in:
Karina Kwiatek 2022-07-31 10:30:14 +02:00 committed by GitHub
commit d9a2e7dde8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 19 deletions

View File

@ -32,8 +32,11 @@ module UseCase
inbox = ::Inbox.create!(user: target_user, question: question, new: true)
{
question: question,
inbox: inbox
status: 201,
resource: question,
extra: {
inbox:
}
}
end

View File

@ -23,7 +23,8 @@ module UseCase
QuestionWorker.perform_async(source_user_id, question.id)
{
question: question
status: 201,
resource: question
}
end

View File

@ -15,6 +15,11 @@ module UseCase
raise Errors::Forbidden unless current_user&.mod? || question.user == current_user
question.destroy!
{
status: 204,
resource: nil,
}
end
end
end

View File

@ -1,13 +1,13 @@
# frozen_string_literal: true
require 'use_case/base'
require "use_case/base"
module UseCase
module User
class Ban < UseCase::Base
REASON_SPAM = 'Spam'
REASON_HARASSMENT = 'Harassment'
REASON_BAN_EVASION = 'Ban evasion'
REASON_SPAM = "Spam"
REASON_HARASSMENT = "Harassment"
REASON_BAN_EVASION = "Ban evasion"
option :target_user_id, type: Types::Coercible::Integer
option :expiry, types: Types::Nominal::DateTime.optional
@ -24,14 +24,18 @@ module UseCase
)
target_user.profile.update!(
display_name: nil,
description: '',
location: '',
website: '',
description: "",
location: "",
website: ""
)
end
{
ban: ban
status: 201,
resource: ban,
extra: {
target_user:
}
}
end
@ -40,11 +44,7 @@ module UseCase
end
def source_user
if source_user_id
@source_user ||= ::User.find(source_user_id)
else
nil
end
@source_user ||= ::User.find(source_user_id) if source_user_id
end
end
end

View File

@ -9,6 +9,14 @@ module UseCase
def call
target_user.unban
{
status: 204,
resource: nil,
extra: {
target_user: target_user
}
}
end
def target_user

View File

@ -19,11 +19,11 @@ describe UseCase::Question::CreateFollowers do
let(:author_identifier) { nil }
it "creates question" do
expect(subject[:question]).to be_persisted
expect(subject[:resource]).to be_persisted
end
it "enqueues a QuestionWorker job" do
expect(QuestionWorker).to have_enqueued_sidekiq_job(source_user.id, subject[:question].id)
expect(QuestionWorker).to have_enqueued_sidekiq_job(source_user.id, subject[:resource].id)
end
end
end