Skip to content

Commit

Permalink
added HW9
Browse files Browse the repository at this point in the history
  • Loading branch information
stepantishhen committed Nov 5, 2023
1 parent 088c13b commit e6620f1
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/interactors/tasks/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@ module Tasks
class Create
include Interactor::Organizer

delegate :project, :task, to: :context

organize Tasks::Creates::PrepareParams,
Tasks::Save
after do
task = context.task
project = task.project
owner = project.users.find_by(project_memberships: { role: "owner" })
members = project.users.where.not(id: owner.id)

TaskMailer.task_created_owner(owner, task).deliver_later if owner.present?
members.each do |member|
TaskMailer.task_created_member(member, task).deliver_later
end
end
end
end
12 changes: 12 additions & 0 deletions app/interactors/tasks/destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@ class Destroy

delegate :task, to: :context

before do
context.task = task
context.project = task.project
context.users = User.where(id: task.project.users.pluck(:id))
end

def call
task.destroy
end

after do
context.users.each do |user|
TaskMailer.task_deleted(user).deliver_later
end
end
end
end
10 changes: 10 additions & 0 deletions app/interactors/tasks/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@ class Update
include Interactor::Organizer

organize Tasks::Save

after do
task = context.task
project = task.project
users = project.users

users.each do |user|
TaskMailer.task_updated(user, task).deliver_later
end
end
end
end
29 changes: 29 additions & 0 deletions app/mailers/task_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class TaskMailer < ApplicationMailer
def task_created_owner(user, task)
@user = user
@task = task
@project = task.project

mail(to: @user.email, subject: "A new task has been successfully created")
end

def task_created_member(user, task)
@user = user
@task = task
@project = task.project

mail(to: @user.email, subject: "A new task has been created in your project")
end

def task_updated(user, task)
@user = user
@task = task
@project = task.project
mail(to: @user.email, subject: "A task in your project has been updated")
end

def task_deleted(user)
@user = user
mail(to: @user.email, subject: "A task in your project has been deleted")
end
end
7 changes: 7 additions & 0 deletions app/views/task_mailer/task_created_member.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>A new task has been created in your project!</h1>
<ul>
<li><strong>Task Name:</strong> <%= @task.name %></li>
<li><strong>Description:</strong> <%= @task.description %></li>
<li><strong>Deadline:</strong> <%= @task.deadline_at.strftime('%B %d, %Y') %></li>
<li><strong>Status:</strong> <%= @task.status.text %></li>
</ul>
8 changes: 8 additions & 0 deletions app/views/task_mailer/task_created_owner.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>A new task "<%= @task.name %>" has been successfully created in your project "<%= @project.name %>"!</h1>
<p>Only for project owner</p>
<ul>
<li><strong>Task Name:</strong> <%= @task.name %></li>
<li><strong>Description:</strong> <%= @task.description %></li>
<li><strong>Deadline:</strong> <%= @task.deadline_at.strftime('%B %d, %Y') %></li>
<li><strong>Status:</strong> <%= @task.status.text %></li>
</ul>
2 changes: 2 additions & 0 deletions app/views/task_mailer/task_deleted.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>A task in your project has been deleted!</h1>
<p>The task "<%= @task.name %>" in the project "<%= @project.name %>" has been deleted.</p>
2 changes: 2 additions & 0 deletions app/views/task_mailer/task_updated.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>A task in your project has been updated!</h1>
<p>The task "<%= @task.name %>" in the project "<%= @project.name %>" has recently been updated.</p>

0 comments on commit e6620f1

Please sign in to comment.