Skip to content

Commit

Permalink
Merge branch 'main' into feature/docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslavrick authored Aug 21, 2023
2 parents e379b07 + 5f2d399 commit 35bafc9
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 146 deletions.
1 change: 1 addition & 0 deletions .overcommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ PreCommit:
RuboCop:
enabled: true
on_warn: fail
command: ['bundle', 'exec', 'rubocop']
Fasterer:
enabled: true
on_warn: fail
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ gem 'hamlit', '~> 3.0.3'
gem 'hamlit-rails', '~> 0.2.3'
gem 'html2haml', '~> 2.2.0'
gem 'importmap-rails', '~> 1.1.5'
gem 'interactor', '~> 3.1.2'
gem 'jbuilder', '~> 2.11.5'
gem 'jquery-rails', '~> 4.5.1'
gem 'nokogiri', '~> 1.15.4'
Expand Down
52 changes: 27 additions & 25 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ GEM
minitest (>= 5.1)
tzinfo (~> 2.0)
ast (2.4.2)
autoprefixer-rails (10.4.7.0)
autoprefixer-rails (10.4.13.0)
execjs (~> 2)
bcrypt (3.1.18)
bindex (0.8.1)
Expand All @@ -93,10 +93,10 @@ GEM
concurrent-ruby (1.2.2)
crass (1.0.6)
date (3.3.3)
debug (1.7.1)
debug (1.7.2)
irb (>= 1.5.0)
reline (>= 0.3.1)
devise (4.9.0)
devise (4.9.2)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
Expand All @@ -119,7 +119,7 @@ GEM
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
railties (>= 5.0.0)
fasterer (0.10.0)
fasterer (0.10.1)
colorize (~> 0.7)
ruby_parser (>= 3.19.1)
ffaker (2.21.0)
Expand Down Expand Up @@ -158,14 +158,15 @@ GEM
haml (>= 4.0, < 6)
nokogiri (>= 1.6.0)
ruby_parser (~> 3.5)
i18n (1.12.0)
i18n (1.13.0)
concurrent-ruby (~> 1.0)
importmap-rails (1.1.5)
importmap-rails (1.1.6)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
iniparse (1.5.0)
interactor (3.1.2)
io-console (0.6.0)
irb (1.6.2)
irb (1.6.4)
reline (>= 0.3.0)
jbuilder (2.11.5)
actionview (>= 5.0.0)
Expand All @@ -178,7 +179,7 @@ GEM
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.19.1)
loofah (2.20.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
lumberjack (1.2.8)
Expand Down Expand Up @@ -213,12 +214,12 @@ GEM
childprocess (>= 0.6.3, < 5)
iniparse (~> 1.4)
rexml (~> 3.2)
pagy (6.0.2)
parallel (1.22.1)
parser (3.2.1.0)
pagy (6.0.3)
parallel (1.23.0)
parser (3.2.2.1)
ast (~> 2.4.1)
pg (1.4.6)
popper_js (2.11.6)
popper_js (2.11.7)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down Expand Up @@ -275,8 +276,8 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (2.7.0)
reline (0.3.2)
regexp_parser (2.8.0)
reline (0.3.3)
io-console (~> 0.5)
require_all (3.0.0)
responders (3.1.0)
Expand All @@ -287,12 +288,12 @@ GEM
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.1)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.3)
rspec-mocks (3.12.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-rails (6.0.1)
Expand All @@ -314,26 +315,26 @@ GEM
rubocop-ast (>= 1.24.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.27.0)
rubocop-ast (1.28.1)
parser (>= 3.2.1.0)
rubocop-capybara (2.17.1)
rubocop-capybara (2.18.0)
rubocop (~> 1.41)
rubocop-md (1.2.0)
rubocop (>= 1.0)
rubocop-performance (1.16.0)
rubocop-performance (1.17.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.18.0)
rubocop-rails (2.19.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.18.1)
rubocop-rspec (2.20.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
ruby-progressbar (1.11.0)
ruby_parser (3.19.2)
ruby-progressbar (1.13.0)
ruby_parser (3.20.0)
sexp_processor (~> 4.16)
sassc (2.4.0)
ffi (~> 1.9)
Expand Down Expand Up @@ -389,7 +390,7 @@ GEM
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.7)
zeitwerk (2.6.8)

PLATFORMS
x86_64-linux
Expand All @@ -412,6 +413,7 @@ DEPENDENCIES
hamlit-rails (~> 0.2.3)
html2haml (~> 2.2.0)
importmap-rails (~> 1.1.5)
interactor (~> 3.1.2)
jbuilder (~> 2.11.5)
jquery-rails (~> 4.5.1)
nokogiri (~> 1.15.4)
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/car_card.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.car-card {
border-radius: 20px;
border-radius: 200px;
}
13 changes: 11 additions & 2 deletions app/controllers/cars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def index
sort
@total_cars_count = @cars.count
@pagy, @cars = pagy @cars
@cars
end

def show
Expand All @@ -20,11 +21,19 @@ def show
def search
return unless params['filter_params'].present? && params['filter_params'].keys.any?

@cars = CarsService::SearchService.new(params: params['filter_params']).call
@cars = search_cars.cars
end

def sort
@cars = CarsService::SortService.new(params: params[:sort_by]).call if valid_sort_params?
@cars = sort_cars.cars if valid_sort_params?
end

def search_cars
Cars::Searcher.call(params: params['filter_params'], cars: @cars)
end

def sort_cars
Cars::Sorter.call(params: params[:sort_by], cars: @cars)
end

def valid_sort_params?
Expand Down
55 changes: 55 additions & 0 deletions app/interactors/cars/searcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

module Cars
class Searcher
include Interactor
def call
search_by_make
search_by_model
search_by_year_from
search_by_year_to
search_by_price_from
search_by_price_to

context.cars
end

private

def search_by_make
return context.cars if context.params['make'].blank?

context.cars = context.cars.filter_by_make(context.params['make'])
end

def search_by_model
return context.cars if context.params['model'].blank?

context.cars = context.cars.filter_by_model(context.params['model'])
end

def search_by_year_from
return context.cars if context.params['year_from'].blank?

context.cars = context.cars.filter_by_year_from(context.params['year_from'].to_i)
end

def search_by_year_to
return context.cars if context.params['year_to'].blank?

context.cars = context.cars.filter_by_year_to(context.params['year_to'].to_i)
end

def search_by_price_from
return context.cars if context.params['price_from'].blank?

context.cars = context.cars.filter_by_price_from(context.params['price_from'].to_i)
end

def search_by_price_to
return context.cars if context.params['price_to'].blank?

context.cars = context.cars.filter_by_price_to(context.params['price_to'].to_i)
end
end
end
13 changes: 13 additions & 0 deletions app/interactors/cars/sorter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Cars
class Sorter
include Interactor

attr_reader :data

def call
context.cars = context.cars.filter_sort_by(context.params)
end
end
end
10 changes: 5 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

class User < ApplicationRecord
has_many :searches, dependent: :delete_all

validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
validates :password, length: { within: 8..128 }

# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable

validates :email, presence: true
validates :email, uniqueness: true

has_many :searches, dependent: :delete_all
end
58 changes: 0 additions & 58 deletions app/queries/cars_service/search_service.rb

This file was deleted.

16 changes: 0 additions & 16 deletions app/queries/cars_service/sort_service.rb

This file was deleted.

2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@

# ==> Configuration for :validatable
# Range for password length.
config.password_length = 6..128
config.password_length = 8..128

# Email regex used to validate email formats. It simply asserts that
# one (and only one) @ exists in the given string. This is mainly
Expand Down
Loading

0 comments on commit 35bafc9

Please sign in to comment.