Skip to content

Commit

Permalink
Merge pull request #1025 from seedcommons/sc_websitesite_api_address
Browse files Browse the repository at this point in the history
Addresses modifications API
  • Loading branch information
Novruu authored Dec 2, 2024
2 parents 69111b1 + 703f955 commit 5d08db3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
30 changes: 26 additions & 4 deletions app/controllers/api/v1/divisions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ class DivisionsController < ApplicationController
#Deshabilita CSRF protection
skip_before_action :verify_authenticity_token, only: [:add_address, :remove_address]

=begin
def index
def index_with_address
#seed_commons_id = Division.find_by(name: "Seed Commons").id
seed_commons_division_ids = Division.find_by(name: "Seed Commons").self_and_descendants.pluck(:id)
#divisions = Division.includes(address: [:country, :geo_state]).where(parent_id: seed_commons_id, public: true)
divisions = Division.includes(address: [:country, :geo_state]).where(parent_id: seed_commons_division_ids).where.not(address_id: nil).order(name: :asc)
render json: divisions.map { |division| format_division(division) }
end

def index_all
#seed_commons_id = Division.find_by(name: "Seed Commons").id
seed_commons_division_ids = Division.find_by(name: "Seed Commons").self_and_descendants.pluck(:id)
#divisions = Division.includes(address: [:country, :geo_state]).where(parent_id: seed_commons_id, public: true)
divisions = Division.includes(address: [:country, :geo_state]).where(parent_id: seed_commons_division_ids, public: true)
divisions = Division.includes(address: [:country, :geo_state]).where(parent_id: seed_commons_division_ids).order(name: :asc)
render json: divisions.map { |division| format_division(division) }
end
=end

def index
divisions = [
Expand Down Expand Up @@ -368,8 +374,10 @@ def set_division
end
end

=begin
def format_division(division)
{
id: division.id,
name: division.name,
public_url: public_division_url(division.short_name),
website: division.homepage,
Expand All @@ -384,6 +392,20 @@ def format_division(division)
labely: division.address&.geo_labely
}
end
=end

def format_division(division)
{
id: division.id,
division: division.name,
lat: division.address&.geo_lat,
long: division.address&.geo_long,
movex: division.address&.geo_labelx,
movey: division.address&.geo_labely,
website: division.homepage,
address_id: division.address_id
}
end

def authenticate_api_user
authenticate_or_request_with_http_basic do |username, password|
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
post 'address', on: :member, to: 'divisions#add_address'
delete 'address', on: :member, to: 'divisions#remove_address'
end
get 'divisions/with_address', to: 'divisions#index_with_address'
get 'divisions/all', to: 'divisions#index_all'

resources :loans, only: [:index]
resources :addresses
end
Expand Down

0 comments on commit 5d08db3

Please sign in to comment.