diff --git a/lib/use_case/question/create.rb b/lib/use_case/question/create.rb index 1904f6f6..7a5e0f56 100644 --- a/lib/use_case/question/create.rb +++ b/lib/use_case/question/create.rb @@ -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 diff --git a/lib/use_case/question/create_followers.rb b/lib/use_case/question/create_followers.rb index 23695a74..cce75f76 100644 --- a/lib/use_case/question/create_followers.rb +++ b/lib/use_case/question/create_followers.rb @@ -23,7 +23,8 @@ module UseCase QuestionWorker.perform_async(source_user_id, question.id) { - question: question + status: 201, + resource: question } end diff --git a/lib/use_case/question/destroy.rb b/lib/use_case/question/destroy.rb index 5ffc8f54..e41043a1 100644 --- a/lib/use_case/question/destroy.rb +++ b/lib/use_case/question/destroy.rb @@ -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 diff --git a/lib/use_case/user/ban.rb b/lib/use_case/user/ban.rb index ad032ef8..12d0d8d1 100644 --- a/lib/use_case/user/ban.rb +++ b/lib/use_case/user/ban.rb @@ -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 @@ -20,18 +20,22 @@ module UseCase if reason == REASON_SPAM target_user.update!( profile_picture: nil, - profile_header: nil + profile_header: nil ) 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 diff --git a/lib/use_case/user/unban.rb b/lib/use_case/user/unban.rb index a1f191e1..55e15991 100644 --- a/lib/use_case/user/unban.rb +++ b/lib/use_case/user/unban.rb @@ -9,6 +9,14 @@ module UseCase def call target_user.unban + + { + status: 204, + resource: nil, + extra: { + target_user: target_user + } + } end def target_user diff --git a/spec/lib/use_case/question/create_followers_spec.rb b/spec/lib/use_case/question/create_followers_spec.rb index 0ee8475e..2b310427 100644 --- a/spec/lib/use_case/question/create_followers_spec.rb +++ b/spec/lib/use_case/question/create_followers_spec.rb @@ -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