Skip to content

Commit

Permalink
Merge pull request #7175 from fjordllc/feature/unify-newspaper-argume…
Browse files Browse the repository at this point in the history
…nts-with-hash_1/2

newspaperの引数をハッシュでの受け渡しに統一 1/2
  • Loading branch information
komagata authored Jan 24, 2024
2 parents 6a43d3b + b623aca commit 31eb0a9
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def destroy
# 制限をかけておく
redirect_to admin_users_url, alert: '自分自身を削除する場合、退会から処理を行ってください。' if current_user.id == params[:id]
user = User.find(params[:id])
Newspaper.publish(:learning_destroy, user)
Newspaper.publish(:learning_destroy, { user: })
user.destroy
redirect_to admin_users_url, notice: "#{user.name} さんを削除しました。"
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/checks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create
user: current_user,
checkable: checkable
)
Newspaper.publish(:check_create, @check)
Newspaper.publish(:check_create, { check: @check })
head :created
else
render json: { message: "この#{checkable.class.model_name.human}は確認済です。" }, status: :unprocessable_entity
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/practices/learning_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def update
status = learning.new_record? ? :created : :ok

if learning.save
Newspaper.publish(:learning_create, learning.user)
Newspaper.publish(:learning_create, { user: learning.user })
notify_to_chat_for_employment_counseling(learning) if status == :created && learning.practice.title == '就職相談部屋を作る'
head status
else
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comeback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create
if @user
if @user&.hibernated?
@user.comeback!
Newspaper.publish(:comeback_update, @user)
Newspaper.publish(:comeback_update, { user: @user })
@user.create_comebacked_comment
redirect_to root_url, notice: '休会から復帰しました。'
else
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def create
set_wip
update_published_at
if @product.save
Newspaper.publish(:product_create, @product)
Newspaper.publish(:product_save, @product)
Newspaper.publish(:product_create, { product: @product })
Newspaper.publish(:product_save, { product: @product })
redirect_to Redirection.determin_url(self, @product), notice: notice_message(@product, :create)
else
render :new
Expand All @@ -56,7 +56,7 @@ def update
update_published_at
if @product.update(product_params)
Newspaper.publish(:product_update, { product: @product, current_user: current_user })
Newspaper.publish(:product_save, @product)
Newspaper.publish(:product_save, { product: @product })
notice_another_mentor_assigned_as_checker
redirect_to Redirection.determin_url(self, @product), notice: notice_message(@product, :update)
else
Expand Down
3 changes: 2 additions & 1 deletion app/models/comeback_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class ComebackNotifier
def call(user)
def call(payload)
user = payload[:user]
User.admins_and_mentors.each do |admin_or_mentor|
ActivityDelivery.with(sender: user, receiver: admin_or_mentor).notify(:comebacked)
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/comment/after_create_callback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def after_commit(comment)
create_watch(comment)
notify_to_watching_user(comment)
elsif comment.sender != comment.receiver
Newspaper.publish(:came_comment, comment)
Newspaper.publish(:came_comment, { comment: })
end

if comment.commentable.instance_of?(Talk)
Expand Down Expand Up @@ -74,7 +74,7 @@ def delete_assigned_and_unreplied_product_count_cache(comment)
end

def notify_to_admins(comment)
Newspaper.publish(:came_comment_in_talk, comment)
Newspaper.publish(:came_comment_in_talk, { comment: })
end

def update_action_completed(comment)
Expand Down
3 changes: 2 additions & 1 deletion app/models/comment_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class CommentNotifier
def call(comment)
def call(payload)
comment = payload[:comment]
return if comment.nil?

commentable_path = Rails.application.routes.url_helpers.polymorphic_path(comment.commentable)
Expand Down
3 changes: 2 additions & 1 deletion app/models/comment_notifier_for_admin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class CommentNotifierForAdmin
def call(comment)
def call(payload)
comment = payload[:comment]
return if comment.nil?

User.admins.each do |admin_user|
Expand Down
3 changes: 2 additions & 1 deletion app/models/learning_cache_destroyer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class LearningCacheDestroyer
def call(user)
def call(payload)
user = payload[:user]
Rails.cache.delete "/model/user/#{user.id}/completed_percentage"
end
end
8 changes: 1 addition & 7 deletions app/models/learning_status_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

class LearningStatusUpdater
def call(payload)
product_or_associated_object =
case payload
when Hash
payload[:product]
else
payload
end
product_or_associated_object = payload[:product] || payload[:check]
case product_or_associated_object
when Product
update_after_submission(product_or_associated_object)
Expand Down
3 changes: 2 additions & 1 deletion app/models/product_author_watcher.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class ProductAuthorWatcher
def call(product)
def call(payload)
product = payload[:product]
Watch.create!(user: product.user, watchable: product)
end
end
8 changes: 1 addition & 7 deletions app/models/product_notifier_for_colleague.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

class ProductNotifierForColleague
def call(payload)
product =
case payload
when Hash
payload[:product]
else
payload
end
product = payload[:product]
return if product.wip

notify_advisers product if product.user.trainee? && product.user.company
Expand Down
3 changes: 2 additions & 1 deletion app/models/product_notifier_for_practice_watcher.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class ProductNotifierForPracticeWatcher
def call(product)
def call(payload)
product = payload[:product]
return if product.wip

practice = Practice.find(product.practice_id)
Expand Down
2 changes: 1 addition & 1 deletion test/models/product_notifier_for_practice_watcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ProductNotifierForPracticeWatcherTest < ActiveSupport::TestCase
product.save!

perform_enqueued_jobs do
ProductNotifierForPracticeWatcher.new.call(product)
ProductNotifierForPracticeWatcher.new.call({ product: })
end
assert Notification.where(user_id: watch.user_id, sender_id: product.user_id,
message: "#{product.user.login_name}さんが「#{product.practice.title}」の提出物を提出しました。").exists?
Expand Down

0 comments on commit 31eb0a9

Please sign in to comment.