Skip to content

Commit

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

newspaperの引数をハッシュでの受け渡しに統一 2/2
  • Loading branch information
komagata authored Jan 24, 2024
2 parents c9d646e + 88dedbc commit 6a43d3b
Show file tree
Hide file tree
Showing 38 changed files with 85 additions and 64 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 @@ -23,7 +23,7 @@ def edit; end
def update
if @user.update(user_params)
destroy_subscription(@user)
Newspaper.publish(:retirement_create, @user) if @user.saved_change_to_retired_on?
Newspaper.publish(:retirement_create, { user: @user }) if @user.saved_change_to_retired_on?
redirect_to admin_users_url, notice: 'ユーザー情報を更新しました。'
else
render :edit
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/announcements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def update
set_wip

if @announcement.update(announcement_params)
Newspaper.publish(:announcement_update, @announcement)
Newspaper.publish(:announcement_update, { announcement: @announcement })
redirect_to Redirection.determin_url(self, @announcement), notice: notice_message(@announcement)
else
render :edit
Expand All @@ -50,7 +50,7 @@ def create
@announcement.user_id = current_user.id
set_wip
if @announcement.save
Newspaper.publish(:announcement_create, @announcement)
Newspaper.publish(:announcement_create, { announcement: @announcement })
redirect_to Redirection.determin_url(self, @announcement), notice: notice_message(@announcement)
else
render :new
Expand All @@ -59,7 +59,7 @@ def create

def destroy
@announcement.destroy
Newspaper.publish(:announcement_destroy, @announcement)
Newspaper.publish(:announcement_destroy, { announcement: @announcement })
redirect_to announcements_path, notice: 'お知らせを削除しました'
end

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/api/answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def create
@answer = question.answers.new(answer_params)
@answer.user = current_user
if @answer.save
Newspaper.publish(:answer_create, @answer)
Newspaper.publish(:answer_save, @answer)
Newspaper.publish(:answer_create, { answer: @answer })
Newspaper.publish(:answer_save, { answer: @answer })
render :create, status: :created
else
head :bad_request
Expand All @@ -39,7 +39,7 @@ def create

def update
if @answer.update(answer_params)
Newspaper.publish(:answer_save, @answer)
Newspaper.publish(:answer_save, { answer: @answer })
head :ok
else
head :bad_request
Expand All @@ -48,7 +48,7 @@ def update

def destroy
@answer.destroy
Newspaper.publish(:answer_destroy, @answer)
Newspaper.publish(:answer_destroy, { answer: @answer })
end

private
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/api/correct_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def create
@answer = @question.answers.find(params[:answer_id])
@answer.type = 'CorrectAnswer'
if @answer.save
Newspaper.publish(:answer_save, @answer)
Newspaper.publish(:correct_answer_save, @answer)
Newspaper.publish(:answer_save, { answer: @answer })
Newspaper.publish(:correct_answer_save, { answer: @answer })
ChatNotifier.message("質問:「#{@answer.question.title}」のベストアンサーが選ばれました。\r#{url_for(@answer.question)}")
render json: @answer
else
Expand All @@ -20,7 +20,7 @@ def create
def update
answer = @question.answers.find(params[:answer_id])
answer.update!(type: '')
Newspaper.publish(:answer_save, @answer)
Newspaper.publish(:answer_save, { answer: @answer })
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def show
def update
question = Question.find(params[:id])
if question.update(question_params)
Newspaper.publish(:question_update, question) if question.saved_change_to_wip?
Newspaper.publish(:question_update, { question: }) if question.saved_change_to_wip?
head :ok
else
head :bad_request
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create
set_wip
if @event.save
update_published_at
Newspaper.publish(:event_create, @event)
Newspaper.publish(:event_create, { event: @event })
url = publish_with_announcement? ? new_announcement_path(event_id: @event.id) : Redirection.determin_url(self, @event)
redirect_to url, notice: notice_message(@event)
else
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/graduation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GraduationController < ApplicationController
def update
if @user.update(graduated_on: Date.current)
Subscription.new.destroy(@user.subscription_id) if @user.subscription_id
Newspaper.publish(:graduation_update, @user)
Newspaper.publish(:graduation_update, { user: @user })
redirect_to @redirect_url, notice: 'ユーザー情報を更新しました。'
else
redirect_to @redirect_url, alert: 'ユーザー情報の更新に失敗しました'
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create
if @page.save
url = Redirection.determin_url(self, @page)
if !@page.wip?
Newspaper.publish(:page_create, @page)
Newspaper.publish(:page_create, { page: @page })
url = new_announcement_url(page_id: @page.id) if @page.announcement_of_publication?
end

Expand All @@ -60,7 +60,7 @@ def update
if @page.update(page_params)
url = Redirection.determin_url(self, @page)
if @page.saved_change_to_attribute?(:wip, from: true, to: false) && @page.published_at.nil?
Newspaper.publish(:page_update, @page)
Newspaper.publish(:page_update, { page: @page })
url = new_announcement_path(page_id: @page.id) if @page.announcement_of_publication?
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def create
@question.user = current_user
@question.wip = params[:commit] == 'WIP'
if @question.save
Newspaper.publish(:question_create, @question)
Newspaper.publish(:question_create, { question: @question })
redirect_to @question, notice: notice_message(@question)
else
render :new
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/regular_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create
if @regular_event.save
update_publised_at
Organizer.create(user_id: current_user.id, regular_event_id: @regular_event.id)
Newspaper.publish(:event_create, @regular_event)
Newspaper.publish(:event_create, { event: @regular_event })
set_all_user_participants_and_watchers
path = publish_with_announcement? ? new_announcement_path(regular_event_id: @regular_event.id) : Redirection.determin_url(self, @regular_event)
redirect_to path, notice: notice_message(@regular_event)
Expand All @@ -40,7 +40,7 @@ def update
set_wip
if @regular_event.update(regular_event_params)
update_publised_at
Newspaper.publish(:regular_event_update, @regular_event)
Newspaper.publish(:regular_event_update, { regular_event: @regular_event })
set_all_user_participants_and_watchers
path = publish_with_announcement? ? new_announcement_path(regular_event_id: @regular_event.id) : Redirection.determin_url(self, @regular_event)
redirect_to path, notice: notice_message(@regular_event)
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def create
set_wip
canonicalize_learning_times(@report)
if @report.save
Newspaper.publish(:report_save, @report)
Newspaper.publish(:report_save, { report: @report })
redirect_to redirect_url(@report), notice: notice_message(@report), flash: flash_contents(@report)
else
render :new
Expand All @@ -63,7 +63,7 @@ def update
@report.assign_attributes(report_params)
canonicalize_learning_times(@report)
if @report.save
Newspaper.publish(:report_save, @report)
Newspaper.publish(:report_save, { report: @report })
redirect_to redirect_url(@report), notice: notice_message(@report), flash: flash_contents(@report)
else
render :edit
Expand All @@ -72,7 +72,7 @@ def update

def destroy
@report.destroy
Newspaper.publish(:report_destroy, @report)
Newspaper.publish(:report_destroy, { report: @report })
redirect_to reports_url, notice: '日報を削除しました。'
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/retirement_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create
if current_user.save(context: :retirement)
user = current_user
current_user.delete_and_assign_new_organizer
Newspaper.publish(:retirement_create, user)
Newspaper.publish(:retirement_create, { user: })
begin
UserMailer.retire(user).deliver_now
rescue Postmark::InactiveRecipientError => e
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/scheduler/daily/auto_retire_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def auto_retire
user.hibernated_at = nil
user.save!(validate: false)

Newspaper.publish(:retirement_create, user)
Newspaper.publish(:retirement_create, { user: })
begin
UserMailer.auto_retire(user).deliver_now
rescue Postmark::InactiveRecipientError => e
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def create
@user.course_id ||= Course.first.id
@user.free = true if @user.trainee?
@user.build_discord_profile
Newspaper.publish(:user_create, @user)
Newspaper.publish(:user_create, { user: @user })
if @user.staff? || @user.trainee?
create_free_user!
else
Expand Down Expand Up @@ -95,7 +95,7 @@ def create_free_user!
UserMailer.welcome(@user).deliver_now
notify_to_mentors(@user)
notify_to_chat(@user)
Newspaper.publish(:student_or_trainee_create, @user) if @user.trainee?
Newspaper.publish(:student_or_trainee_create, { user: @user }) if @user.trainee?
logger.info "[Signup] 4. after create times channel for free user. #{@user.email}"
redirect_to root_url, notice: 'サインアップメールをお送りしました。メールからサインアップを完了させてください。'
else
Expand Down Expand Up @@ -141,7 +141,7 @@ def create_user!
UserMailer.welcome(@user).deliver_now
notify_to_mentors(@user)
notify_to_chat(@user)
Newspaper.publish(:student_or_trainee_create, @user) if @user.student?
Newspaper.publish(:student_or_trainee_create, { user: @user }) if @user.student?
logger.info "[Signup] 8. after create times channel. #{@user.email}"
redirect_to root_url, notice: 'サインアップメールをお送りしました。メールからサインアップを完了させてください。'
else
Expand Down
3 changes: 2 additions & 1 deletion app/models/ai_answer_creator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class AIAnswerCreator
def call(question)
def call(payload)
question = payload[:question]
question.update(ai_answer: '')
AIAnswerCreateJob.perform_later(question_id: question.id)
end
Expand Down
5 changes: 3 additions & 2 deletions app/models/announcement_notification_destroyer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class AnnouncementNotificationDestroyer
def call(announce)
Notification.where(link: "/announcements/#{announce.id}").destroy_all
def call(payload)
announcement = payload[:announcement]
Notification.where(link: "/announcements/#{announcement.id}").destroy_all
end
end
17 changes: 9 additions & 8 deletions app/models/announcement_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# frozen_string_literal: true

class AnnouncementNotifier
def call(announce)
return if announce.wip? || announce.published_at?
def call(payload)
announcement = payload[:announcement]
return if announcement.wip? || announcement.published_at?

announce.update(published_at: Time.current)
DiscordNotifier.with(announce: announce).announced.notify_now
Watch.create!(user: announce.user, watchable: announce)
announcement.update(published_at: Time.current)
DiscordNotifier.with(announce: announcement).announced.notify_now
Watch.create!(user: announcement.user, watchable: announcement)

target_users = User.announcement_receiver(announce.target)
target_users = User.announcement_receiver(announcement.target)
target_users.each do |target|
next if announce.sender == target
next if announcement.sender == target

ActivityDelivery.with(announcement: announce, receiver: target).notify(:post_announcement)
ActivityDelivery.with(announcement:, receiver: target).notify(:post_announcement)
end
end
end
3 changes: 2 additions & 1 deletion app/models/answer_cache_destroyer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class AnswerCacheDestroyer
def call(_answer)
def call(payload)
_answer = payload[:answer]
Cache.delete_not_solved_question_count
end
end
3 changes: 2 additions & 1 deletion app/models/answer_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class AnswerNotifier
def call(answer)
def call(payload)
answer = payload[:answer]
return if answer.sender == answer.receiver

question = answer.question
Expand Down
3 changes: 2 additions & 1 deletion app/models/answerer_watcher.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class AnswererWatcher
def call(answer)
def call(payload)
answer = payload[:answer]
question = Question.find(answer.question_id)

return if question.watches.pluck(:user_id).include?(answer.sender.id)
Expand Down
3 changes: 2 additions & 1 deletion app/models/correct_answer_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class CorrectAnswerNotifier
def call(answer)
def call(payload)
answer = payload[:answer]
notify_correct_answer(answer) if answer.saved_change_to_attribute?('type', to: 'CorrectAnswer')
end

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

class EventOrganizerWatcher
def call(event)
def call(payload)
event = payload[:event]
Watch.create!(user: event.user, watchable: event)
end
end
3 changes: 2 additions & 1 deletion app/models/first_report_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class FirstReportNotifier
def call(report)
def call(payload)
report = payload[:report]
return if report.wip || !report.first? || Notification.find_by(kind: :first_report, sender_id: report.user.id).present?

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

class GraduationNotifier
def call(user)
def call(payload)
user = payload[:user]
User.mentor.each do |mentor|
ActivityDelivery.with(sender: user, receiver: mentor).notify(:graduated)
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/mentors_watch_for_question_creator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class MentorsWatchForQuestionCreator
def call(question)
def call(payload)
question = payload[:question]
return if question.wip? || question.watched?

watch_question_records = watch_records(question)
Expand Down
3 changes: 2 additions & 1 deletion app/models/notifier_to_watching_user.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class NotifierToWatchingUser
def call(answer)
def call(payload)
answer = payload[:answer]
question = Question.find(answer.question_id)
mention_user_ids = answer.new_mention_users.ids

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

class PageNotifier
def call(page)
def call(payload)
page = payload[:page]
send_notification(page)
notify_to_chat(page)

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

class QuestionNotifier
def call(question)
def call(payload)
question = payload[:question]
return if question.wip?

ChatNotifier.message(<<~TEXT)
Expand Down
3 changes: 2 additions & 1 deletion app/models/regular_event_update_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class RegularEventUpdateNotifier
def call(regular_event)
def call(payload)
regular_event = payload[:regular_event]
participants = regular_event.participants

participants.each do |participant|
Expand Down
Loading

0 comments on commit 6a43d3b

Please sign in to comment.