Browse Source

Merge branch 'feature/local_and_pub_api' into develop

* feature/local_and_pub_api:
  Split bragi into local/private and remote/public URL
  DRY up the common query items into superclass
tags/0.3.6^2
Bèr Kessels 1 month ago
parent
commit
16174feba9

+ 10
- 11
app/projections/base_query.rb View File

@@ -7,23 +7,22 @@ module Hours
##
# Common behaviour for all query objects
class BaseQuery
DEFAULT_DATASET = Hours.projections_database[:query_places]
BUFFERX = 0.005302691970002
BUFFERY = 0.01297116279602
attr_reader :dataset, :page

attr_reader :page
include Pagy::Backend

def initialize(dataset)
@dataset = dataset
@page = nil
def self.build
faraday = Faraday.new(url: ENV['BRAGI_PRIVATE_URL']) do |conn|
conn.response :raise_error
conn.adapter Faraday.default_adapter
end
new(faraday)
end

def self.build
new(DEFAULT_DATASET)
def initialize(http_client)
@http_client = http_client
end

def pagy_get_vars(collection, vars)
def pagy_array_get_vars(collection, vars)
vars[:count] = collection.count
vars[:page] = page
vars

+ 1
- 22
app/projections/city_query.rb View File

@@ -6,22 +6,7 @@ require 'pagy/extras/array'
module Hours
module Projections
# Query handler that builds a list of places in a City
class CityQuery
attr_reader :page
include Pagy::Backend

def self.build
faraday = Faraday.new(url: ENV['BRAGI_URL']) do |conn|
conn.response :raise_error
conn.adapter Faraday.default_adapter
end
new(faraday)
end

def initialize(http_client)
@http_client = http_client
end

class CityQuery < BaseQuery
def handle(slug, page = 1)
@slug = slug
@page = page
@@ -32,12 +17,6 @@ module Hours
@city
end

def pagy_array_get_vars(collection, vars)
vars[:count] = collection.count
vars[:page] = page
vars
end

private

def city

+ 1
- 13
app/projections/place_query.rb View File

@@ -3,19 +3,7 @@
module Hours
module Projections
# Query handler that queries the projection table for a single node
class PlaceQuery
def self.build
faraday = Faraday.new(url: ENV['BRAGI_URL']) do |conn|
conn.response :raise_error
conn.adapter Faraday.default_adapter
end
new(faraday)
end

def initialize(http_client)
@http_client = http_client
end

class PlaceQuery < BaseQuery
def handle(id)
response = @http_client.get("features/#{id}")
@place = Hours::Models::Place.from_geojson_feature(

+ 1
- 25
app/projections/search_query.rb View File

@@ -8,23 +8,7 @@ require 'rgeo/geo_json'
module Hours
module Projections
# Query handler that queries bragi, the rest backend for a string
class SearchQuery
include Pagy::Backend

attr_accessor :page

def self.build
faraday = Faraday.new(url: ENV['BRAGI_URL']) do |conn|
conn.response :raise_error
conn.adapter Faraday.default_adapter
end
new(faraday)
end

def initialize(http_client)
@http_client = http_client
end

class SearchQuery < BaseQuery
def handle(query, page = 1)
@page = page
features = get_bragi_features(query)
@@ -38,14 +22,6 @@ module Hours
Hours::Models::SearchResult.new(error: e.message)
end

protected

def pagy_array_get_vars(array, vars = {})
vars[:count] = array.size
vars[:page] = page
vars
end

private

def get_bragi_features(query)

+ 1
- 1
lib/app.rb View File

@@ -67,7 +67,7 @@ module Hours
# Base URL where to find autocomplete server
helpers do
def bragi_url
ENV['BRAGI_URL']
ENV['BRAGI_PUBLIC_URL']
end
end


Loading…
Cancel
Save