Skip to content

Commit

Permalink
materials for lesson 9 (fs#82)
Browse files Browse the repository at this point in the history
* materials for lesson 9

* fixes
  • Loading branch information
DenisZackharov authored Oct 31, 2023
1 parent d23beb8 commit 504719d
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ gem "bcrypt", "~> 3.1.7"

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", ">= 1.4.4", require: false
gem "sidekiq"

group :development, :test do
gem "byebug", platforms: %i[mri mingw x64_mingw]
Expand All @@ -49,6 +50,7 @@ group :development do
gem "web-console", ">= 4.1.0"
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem "letter_opener"
gem "listen", "~> 3.3"
gem "rack-mini-profiler", "~> 2.0"
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ GEM
xpath (~> 3.2)
coderay (1.1.3)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
crass (1.0.6)
date (3.3.3)
enumerize (2.7.0)
Expand Down Expand Up @@ -111,6 +112,10 @@ GEM
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
language_server-protocol (3.17.0.3)
launchy (2.5.2)
addressable (~> 2.8)
letter_opener (1.8.1)
launchy (>= 2.2, < 3)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -194,6 +199,8 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
redis-client (0.18.0)
connection_pool
regexp_parser (2.8.1)
rexml (3.2.6)
rubocop (1.56.4)
Expand Down Expand Up @@ -243,6 +250,11 @@ GEM
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
semantic_range (3.0.0)
sidekiq (7.1.6)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
rack (>= 2.2.4)
redis-client (>= 0.14.0)
spring (4.1.1)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -295,6 +307,7 @@ DEPENDENCIES
interactor (~> 3.0)
jbuilder (~> 2.7)
kaminari
letter_opener
listen (~> 3.3)
pg (~> 1.1)
pry
Expand All @@ -310,6 +323,7 @@ DEPENDENCIES
rubocop-thread_safety
sass-rails (>= 6)
selenium-webdriver (>= 4.0.0.rc1)
sidekiq
spring
turbolinks (~> 5)
tzinfo-data
Expand Down
7 changes: 7 additions & 0 deletions app/interactors/projects/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ module Projects
class Create
include Interactor::Organizer

delegate :project, :user, to: :context

organize Projects::Save,
Projects::Create::CreateOwner

after do
ProjectMailer.project_created(project, user).deliver_later
Projects::CreateDefaultTasksJob.perform_async(project.id)
end
end
end
17 changes: 17 additions & 0 deletions app/jobs/projects/create_default_tasks_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Projects
class CreateDefaultTasksJob
include Sidekiq::Worker

sidekiq_options queue: :default, retry: 3

def perform(project_id)
project = Project.find(project_id)

project.tasks.create(
[
{ name: "Your first task", status: :unstarted, deadline_at: 1.week.from_now }
]
)
end
end
end
7 changes: 7 additions & 0 deletions app/mailers/project_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ProjectMailer < ApplicationMailer
def project_created(project, user)
@project = project

mail(to: user.email)
end
end
2 changes: 2 additions & 0 deletions app/views/project_mailer/project_created.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>New project created.</h1>
<p>Congratulations! You have become the owner of a new project -- "<%= @project.name %>"!</p>
1 change: 1 addition & 0 deletions app/views/project_mailer/project_created.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Congratulations! You have become the owner of a new project -- "<%= @project.name %>"!
6 changes: 5 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
Rails.application.configure do # rubocop:disable Metrics/BlockLength
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded any time
Expand Down Expand Up @@ -73,4 +73,8 @@

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

config.action_mailer.delivery_method = :letter_opener
config.action_mailer.perform_deliveries = true
config.active_job.queue_adapter = :sidekiq
end
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
require "sidekiq/web"

Rails.application.routes.draw do
mount Sidekiq::Web => "/sidekiq"

root "projects#index"
get "login", to: "sessions#new", as: :login
post "login", to: "sessions#create"
Expand Down

0 comments on commit 504719d

Please sign in to comment.