-
Notifications
You must be signed in to change notification settings - Fork 24
Filters by remote_availibity, location, position_type in query object #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
cce6147
63708ca
6e795d1
77d8420
3bf4ac2
2f13e85
ec683c3
7963877
df683d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,23 @@ def call(params) | |
|
|
||
| private | ||
|
|
||
| Container = Module.new do | ||
| extend Transproc::Registry | ||
| import Transproc::HashTransformations | ||
| import Transproc::Coercions | ||
| import Transproc::ClassTransformations | ||
| end | ||
|
|
||
| class Transformer < Transproc::Transformer[Container] | ||
| symbolize_keys | ||
| map_value :remote, t(:to_boolean) | ||
| constructor_inject Queries::Vacancy::SearchQuery | ||
| end | ||
|
|
||
| def search_query | ||
| params[:query] ? search_query_parser.call(params[:query]) : EMPTY_SEARCH_QUERY | ||
| query_attributes = params[:query] ? search_query_parser.call(params[:query]) : EMPTY_SEARCH_QUERY | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а еще лучше, я бы сделал так, что квери парсер возвращал бы сразу что надо, вне зависимости от того, что туда передать, что-то в таком духе: query_attributes = search_query_parser.call(params[:query])
query_attributes # => attributes or initial_attributes |
||
| initial_attributes = { remote: nil, position_type: nil, location: nil } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. я бы в константу это вынес |
||
| Transformer.new.call(initial_attributes.merge(query_attributes)) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,48 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Queries | ||
| class Vacancy | ||
asusikov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| class SearchQuery < Dry::Struct | ||
| attribute :remote, Core::Types::Strict::Bool.optional.default(nil) | ||
| attribute :position_type, Core::Types::VacancyPositionTypes.optional.default(nil) | ||
| attribute :location, Core::Types::Strict::String.optional.default(nil) | ||
| end | ||
| end | ||
|
|
||
| class Vacancy | ||
| attr_reader :repo | ||
|
|
||
| def initialize(repo = VacancyRepository.new) | ||
| @repo = repo | ||
| end | ||
|
|
||
| def all_with_contact(limit:, page:) | ||
| all_with_contact_relation(limit: limit, page: page).to_a | ||
| def all_with_contact(limit:, page:, search_query:) | ||
| all_with_contact_relation(limit: limit, page: page, search_query: search_query).to_a | ||
| end | ||
|
|
||
| def pager_for_all_with_contact(limit:, page:) | ||
| def pager_for_all_with_contact(limit:, page:, search_query:) | ||
| Hanami::Pagination::Pager.new( | ||
| all_with_contact_relation(limit: limit, page: page).pager | ||
| all_with_contact_relation(limit: limit, page: page, search_query: search_query).pager | ||
| ) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def all_with_contact_relation(limit:, page:) | ||
| repo.aggregate(:contact) | ||
| .where(published: true, archived: false, deleted_at: nil) | ||
| .map_to(::Vacancy).order { created_at.desc } | ||
| .per_page(limit).page(page || 1) | ||
| QUERY_MODIFIERS = { | ||
| remote: ->(query, filter_value) { query.where(remote_available: filter_value) }, | ||
| position_type: ->(query, filter_value) { query.where(position_type: filter_value) }, | ||
| location: ->(query, filter_value) { query.where { location.ilike("%#{filter_value}%") } } | ||
| }.freeze | ||
|
|
||
| def all_with_contact_relation(limit:, page:, search_query:) | ||
| query = repo.aggregate(:contact) | ||
| .where(published: true, archived: false, deleted_at: nil) | ||
| search_query.to_h.each do |key, value| | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. реально оптимизировать этот кусок? что бы при
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не совсем понял вопрос There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. может быть: if search_query
...
end
search_query.to_h.each do |key, value| |
||
| modifier = QUERY_MODIFIERS[key] | ||
| query = modifier.call(query, value) if modifier && value | ||
| end | ||
| query.map_to(::Vacancy).order { created_at.desc } | ||
| .per_page(limit).page(page || 1) | ||
| end | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.