Skip to content
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

Ticket #47: Frontend Kategorieauswahl #290

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CitySDK_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Parameters:
| Name | Required | Type | Notes |
|:--|:-:|:--|:--|
| api_key | - | String | API key |
| group | - | String | |
| keywords | - | String | |
| lat | - | String | |
| long | - | String | |

Sample Response:

Expand Down
31 changes: 30 additions & 1 deletion app/controllers/citysdk/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class ServicesController < CitysdkController
# :apidoc: | Name | Required | Type | Notes |
# :apidoc: |:--|:-:|:--|:--|
# :apidoc: | api_key | - | String | API key |
# :apidoc: | group | - | String | |
# :apidoc: | keywords | - | String | |
# :apidoc: | lat | - | String | |
# :apidoc: | long | - | String | |
# :apidoc:
# :apidoc: Sample Response:
# :apidoc:
Expand Down Expand Up @@ -66,7 +70,32 @@ def show
private

def sorted
Service.active.order(main_category_arel_table[:name], sub_category_arel_table[:name])
Service.active.eager_load(:main_category, :sub_category).where(id: regional_services.flatten.uniq)
.order(main_category_arel_table[:name], sub_category_arel_table[:name])
end

def regional_services
if (ag = authority_groups).present?
Responsibility.active.where(group: ag.map(&:id),
category: filtered_main_categories.map(&:categories)).map(&:category_id)
else
filtered_main_categories.map(&:category_ids)
end
end

def authority_groups
if (lat = params[:lat].to_f).positive? && (lon = params[:long].to_f).positive?
ag = AuthorityGroup.active.regional(lat:, lon:)
return ag if ag.none?(&:reference_default)
end
nil
end

def filtered_main_categories
main_category = MainCategory.all
main_category = main_category.where(name: params[:group]) if params[:group].present?
main_category = main_category.where(kind: params[:keywords]) if params[:keywords].present?
main_category
end
end
end
2 changes: 1 addition & 1 deletion app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def to_s
end

def group(lat:, lon:)
responsibilities.regional(lat:, lon:).first&.group ||
responsibilities.active.regional(lat:, lon:).first&.group ||
Group.regional(lat:, lon:).find_by(reference_default: true)
end

Expand Down
Loading