Skip to content

Commit

Permalink
added project mailer
Browse files Browse the repository at this point in the history
  • Loading branch information
stepantishhen committed Oct 31, 2023
1 parent 504719d commit 8c69323
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/interactors/projects/destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ module Projects
class Destroy
include Interactor

delegate :project, to: :context

delegate :project, :user, to: :context
before do
ProjectMailer.project_deleted(project).deliver_later
end
def call
project.destroy
end
Expand Down
6 changes: 4 additions & 2 deletions app/interactors/projects/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ module Projects
class Update
include Interactor

delegate :project, :project_params, to: :context

delegate :project, :project_params, :user, to: :context
before do
ProjectMailer.project_updated(project).deliver_later
end
def call
context.fail!(error: "Invalid data") unless project.update(project_params)
end
Expand Down
12 changes: 12 additions & 0 deletions app/mailers/project_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@ def project_created(project, user)

mail(to: user.email)
end

def project_updated(project)
@project = project

mail(to: project.users.pluck(:email))
end

def project_deleted(project)
@project = project

mail(to: project.users.pluck(:email))
end
end
1 change: 1 addition & 0 deletions app/views/project_mailer/project_deleted.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Congratulations! You project was deleted -- "<%= @project.name %>"!</h1>
1 change: 1 addition & 0 deletions app/views/project_mailer/project_deleted.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Congratulations! You project was deleted -- "<%= @project.name %>"!
2 changes: 2 additions & 0 deletions app/views/project_mailer/project_updated.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Project updated.</h1>
<p>Congratulations! Project was updated -- "<%= @project.name %>"!</p>
1 change: 1 addition & 0 deletions app/views/project_mailer/project_updated.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Congratulations! Project was updated -- "<%= @project.name %>"!

0 comments on commit 8c69323

Please sign in to comment.