aboutsummaryrefslogtreecommitdiff
path: root/web/lib
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2014-09-14 11:07:06 +0200
committerJochen Topf <jochen@topf.org>2014-09-14 11:07:06 +0200
commit9aa36f6bbbe0fb480717c001f36117e5cf3ccf30 (patch)
tree1abccc8a0c7ad26e103136c9d4607bd9aacacfe3 /web/lib
parent4465c66954575f80de0029b7ecd8986adec873b7 (diff)
downloadtaginfo-9aa36f6bbbe0fb480717c001f36117e5cf3ccf30.tar
taginfo-9aa36f6bbbe0fb480717c001f36117e5cf3ccf30.tar.gz
Separate out up API call for key/projects from tag/projects.
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/api/v4/key.rb69
-rw-r--r--web/lib/api/v4/tag.rb10
2 files changed, 74 insertions, 5 deletions
diff --git a/web/lib/api/v4/key.rb b/web/lib/api/v4/key.rb
index 57c6c6e..45a762d 100644
--- a/web/lib/api/v4/key.rb
+++ b/web/lib/api/v4/key.rb
@@ -323,4 +323,73 @@ class Taginfo < Sinatra::Base
return get_wiki_result(res)
end
+ api(4, 'key/projects', {
+ :description => 'Get projects using a given key.',
+ :parameters => {
+ :key => 'Tag key (required).',
+ :query => 'Only show results where the value matches this query (substring match, optional).'
+ },
+ :paging => :optional,
+ :sort => %w( project_name tag ),
+ :result => paging_results([
+ [:project_id, :STRING, 'Project ID'],
+ [:project_name, :STRING, 'Project name'],
+ [:project_icon_url, :STRING, 'Project icon URL'],
+ [:key, :STRING, 'Key'],
+ [:value, :STRING, 'Value'],
+ [:on_node, :BOOL, 'For nodes?'],
+ [:on_way, :BOOL, 'For ways?'],
+ [:on_relation, :BOOL, 'For relations?'],
+ [:on_area, :BOOL, 'For areas?'],
+ [:description, :STRING, 'Description'],
+ [:doc_url, :STRING, 'Documentation URL'],
+ [:icon_url, :STRING, 'Icon URL']
+ ]),
+ :example => { :key => 'highway', :page => 1, :rp => 10, :sortname => 'project_name', :sortorder => 'asc' },
+ :ui => '/keys/highway=residential#projects'
+ }) do
+ key = params[:key]
+ q = like_contains(params[:query])
+ total = @db.select('SELECT count(*) FROM projects.projects p, projects.project_tags t ON p.id=t.project_id').
+ condition("status = 'OK'").
+ condition('key = ?', key).
+ condition_if("value LIKE ? ESCAPE '@' OR name LIKE ? ESCAPE '@'", q, q).
+ get_first_value().to_i
+
+ res = @db.select('SELECT t.project_id, p.name, p.icon_url AS project_icon_url, t.key, t.value, t.description, t.doc_url, t.icon_url, t.on_node, t.on_way, t.on_relation, t.on_area FROM projects.projects p, projects.project_tags t ON p.id=t.project_id').
+ condition("status = 'OK'").
+ condition('key = ?', key).
+ condition_if("value LIKE ? ESCAPE '@' OR name LIKE ? ESCAPE '@'", q, q).
+ order_by(@ap.sortname, @ap.sortorder) { |o|
+ o.project_name 'p.name'
+ o.project_name :key
+ o.project_name :value
+ o.tag :value
+ o.tag 'p.name'
+ }.
+ paging(@ap).
+ execute()
+
+ return JSON.generate({
+ :page => @ap.page,
+ :rp => @ap.results_per_page,
+ :total => total.to_i,
+ :url => request.url,
+ :data => res.map{ |row| {
+ :project_id => row['project_id'],
+ :project_name => row['name'],
+ :project_icon_url => row['project_icon_url'],
+ :key => row['key'],
+ :value => row['value'],
+ :on_node => row['on_node'].to_i == 1,
+ :on_way => row['on_way'].to_i == 1,
+ :on_relation => row['on_relation'].to_i == 1,
+ :on_area => row['on_area'].to_i == 1,
+ :description => row['description'],
+ :doc_url => row['doc_url'],
+ :icon_url => row['icon_url']
+ } }
+ }, json_opts(params[:format]))
+ end
+
end
diff --git a/web/lib/api/v4/tag.rb b/web/lib/api/v4/tag.rb
index 3fe55a4..e1fd2cd 100644
--- a/web/lib/api/v4/tag.rb
+++ b/web/lib/api/v4/tag.rb
@@ -249,10 +249,10 @@ class Taginfo < Sinatra::Base
end
api(4, 'tag/projects', {
- :description => 'Get projects using a given key or tag.',
+ :description => 'Get projects using a given tag.',
:parameters => {
:key => 'Tag key (required).',
- :value => 'Tag value (optional).',
+ :value => 'Tag value (required).',
:query => 'Only show results where the value matches this query (substring match, optional).'
},
:paging => :optional,
@@ -272,7 +272,7 @@ class Taginfo < Sinatra::Base
[:icon_url, :STRING, 'Icon URL']
]),
:example => { :key => 'highway', :value => 'residential', :page => 1, :rp => 10, :sortname => 'project_name', :sortorder => 'asc' },
- :ui => '/keys/highway=residential#projects'
+ :ui => '/tags/highway=residential#projects'
}) do
key = params[:key]
value = params[:value]
@@ -280,14 +280,14 @@ class Taginfo < Sinatra::Base
total = @db.select('SELECT count(*) FROM projects.projects p, projects.project_tags t ON p.id=t.project_id').
condition("status = 'OK'").
condition('key = ?', key).
- condition_if('value = ? OR VALUE IS NULL', value).
+ condition('value = ? OR VALUE IS NULL', value).
condition_if("value LIKE ? ESCAPE '@' OR name LIKE ? ESCAPE '@'", q, q).
get_first_value().to_i
res = @db.select('SELECT t.project_id, p.name, p.icon_url AS project_icon_url, t.key, t.value, t.description, t.doc_url, t.icon_url, t.on_node, t.on_way, t.on_relation, t.on_area FROM projects.projects p, projects.project_tags t ON p.id=t.project_id').
condition("status = 'OK'").
condition('key = ?', key).
- condition_if('value = ? OR VALUE IS NULL', value).
+ condition('value = ? OR VALUE IS NULL', value).
condition_if("value LIKE ? ESCAPE '@' OR name LIKE ? ESCAPE '@'", q, q).
order_by(@ap.sortname, @ap.sortorder) { |o|
o.project_name 'p.name'