Skip to content

Commit 2035247

Browse files
use query param
1 parent f2e7cb0 commit 2035247

File tree

6 files changed

+21
-28
lines changed

6 files changed

+21
-28
lines changed

apps/web/controllers/vacancies/index.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Index
1616

1717
expose :vacancies
1818
expose :pager
19+
expose :search_query
1920

2021
params do
2122
optional(:page).filled
@@ -24,20 +25,15 @@ class Index
2425
end
2526

2627
def call(params)
27-
result = operation.call(search_query: search_query, page: params[:page], remote_query: params[:remote])
28+
@search_query = params[:query] ? search_query_parser.call(params[:query]) : EMPTY_SEARCH_QUERY
29+
result = operation.call(search_query: @search_query, page: params[:page])
2830

2931
case result
3032
when Success
3133
@pager = result.value![:pager]
3234
@vacancies = result.value![:result]
3335
end
3436
end
35-
36-
private
37-
38-
def search_query
39-
params[:query] ? search_query_parser.call(params[:query]) : EMPTY_SEARCH_QUERY
40-
end
4137
end
4238
end
4339
end

apps/web/views/vacancies/index.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ def remote_filter_button(text:, remote_value:)
5555
private
5656

5757
def current_remote_query
58-
params[:remote] if params[:remote] == 'true' || params[:remote] == 'false'
58+
search_query[:remote] if search_query[:remote] == 'true' || search_query[:remote] == 'false'
5959
end
6060

6161
def remote_filter_button_href(remote_value)
62-
routes.root_path(remote_value.nil? ? {} : { remote: remote_value })
62+
routes.root_path(remote_value.nil? ? {} : { query: "remote:#{remote_value}" })
6363
end
6464
end
6565
end

lib/vacancies/operations/list.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class List < ::Libs::Operation
99

1010
PAGINATION_LIMIT = 10
1111

12-
def call(search_query: {}, page: 1, remote_query: nil) # rubocop:disable Lint/UnusedMethodArgument
13-
remote_available = { 'true' => true, 'false' => false }[remote_query]
12+
def call(search_query: {}, page: 1) # rubocop:disable Lint/UnusedMethodArgument
13+
remote_available = { 'true' => true, 'false' => false }[search_query[:remote]]
1414
pager = vacancy_query.pager_for_all_with_contact(limit: PAGINATION_LIMIT,
1515
page: page || 1,
1616
remote_available: remote_available)

spec/vacancies/operations/list_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
end
2727

2828
context 'with remote query' do
29-
subject { operation.call(remote_query: remote_query) }
29+
subject { operation.call(search_query: { remote: remote_query }) }
3030

3131
let(:vacancies) { [] }
3232

spec/web/controllers/vacancies/index_spec.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,12 @@
1919
end
2020

2121
context 'when params includes query param' do
22-
let(:params) { { query: 'remote:true search text', remote: 'remote_query' } }
22+
let(:params) { { query: 'remote:true search text' } }
2323

2424
it { expect(subject).to be_success }
2525

2626
it do
27-
expect(operation).to receive(:call).with(
28-
page: nil,
29-
search_query: { remote: 'true', text: 'search text' },
30-
remote_query: 'remote_query'
31-
)
27+
expect(operation).to receive(:call).with(page: nil, search_query: { remote: 'true', text: 'search text' })
3228
subject
3329
end
3430
end

spec/web/views/vacancies/index_spec.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
RSpec.describe Web::Views::Vacancies::Index, type: :view do
44
let(:params) { Hash[] }
5-
let(:exposures) { Hash[format: :html, flash: {}, vacancies: [], params: params] }
5+
let(:search_query) { Hash[] }
6+
let(:exposures) { Hash[format: :html, flash: {}, params: params, vacancies: [], search_query: search_query] }
67
let(:template) { Hanami::View::Template.new('apps/web/templates/vacancies/index.html.slim') }
78
let(:view) { described_class.new(template, exposures) }
89
let(:rendered) { view.render }
@@ -20,49 +21,49 @@
2021
expect(rendered).to include without_indentation <<~HTML
2122
<div class="btn-group btn-group-toggle">
2223
<a class="btn btn-light active"><span>Любые</span></a>
23-
<a class="btn btn-light" href="/?remote=true"><span>Удаленные</span></a>
24-
<a class="btn btn-light" href="/?remote=false"><span>В офисе</span></a>
24+
<a class="btn btn-light" href="/?query=remote%3Atrue"><span>Удаленные</span></a>
25+
<a class="btn btn-light" href="/?query=remote%3Afalse"><span>В офисе</span></a>
2526
</div>
2627
HTML
2728
end
2829

2930
context 'when remote is true' do
30-
let(:params) { Hash[remote: 'true'] }
31+
let(:search_query) { Hash[remote: 'true'] }
3132

3233
it do
3334
expect(rendered).to include without_indentation <<~HTML
3435
<div class="btn-group btn-group-toggle">
3536
<a class="btn btn-light" href="/"><span>Любые</span></a>
3637
<a class="btn btn-light active"><span>Удаленные</span></a>
37-
<a class="btn btn-light" href="/?remote=false"><span>В офисе</span></a>
38+
<a class="btn btn-light" href="/?query=remote%3Afalse"><span>В офисе</span></a>
3839
</div>
3940
HTML
4041
end
4142
end
4243

4344
context 'when remote is false' do
44-
let(:params) { Hash[remote: 'false'] }
45+
let(:search_query) { Hash[remote: 'false'] }
4546

4647
it do
4748
expect(rendered).to include without_indentation <<~HTML
4849
<div class="btn-group btn-group-toggle">
4950
<a class="btn btn-light" href="/"><span>Любые</span></a>
50-
<a class="btn btn-light" href="/?remote=true"><span>Удаленные</span></a>
51+
<a class="btn btn-light" href="/?query=remote%3Atrue"><span>Удаленные</span></a>
5152
<a class="btn btn-light active"><span>В офисе</span></a>
5253
</div>
5354
HTML
5455
end
5556
end
5657

5758
context 'when remote is not valid' do
58-
let(:params) { Hash[remote: 'foo'] }
59+
let(:search_query) { Hash[remote: 'foo'] }
5960

6061
it do
6162
expect(rendered).to include without_indentation <<~HTML
6263
<div class="btn-group btn-group-toggle">
6364
<a class="btn btn-light active"><span>Любые</span></a>
64-
<a class="btn btn-light" href="/?remote=true"><span>Удаленные</span></a>
65-
<a class="btn btn-light" href="/?remote=false"><span>В офисе</span></a>
65+
<a class="btn btn-light" href="/?query=remote%3Atrue"><span>Удаленные</span></a>
66+
<a class="btn btn-light" href="/?query=remote%3Afalse"><span>В офисе</span></a>
6667
</div>
6768
HTML
6869
end

0 commit comments

Comments
 (0)