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) inbox = ::Inbox.create!(user: target_user, question: question, new: true)
{ {
question: question, status: 201,
inbox: inbox resource: question,
extra: {
inbox:
}
} }
end end

View File

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

View File

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

View File

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

View File

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

View File

@ -19,11 +19,11 @@ describe UseCase::Question::CreateFollowers do
let(:author_identifier) { nil } let(:author_identifier) { nil }
it "creates question" do it "creates question" do
expect(subject[:question]).to be_persisted expect(subject[:resource]).to be_persisted
end end
it "enqueues a QuestionWorker job" do 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 end
end end