Browse Source

Add search endpoint to render a search result.

develop
Bèr Kessels 3 months ago
parent
commit
56af164922

+ 21
- 0
app/views/search.erb View File

@@ -0,0 +1,21 @@
<h2>Zoekresultaat voor <%= @search_result.query %></h2>

<section class="row">
<div class="col-3 list-group">
<%- @search_result.each do |place| %>
<a href="/places/<%= place.id %>" class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between">
<h3 class="mb-1 small"><%= place.name %></h3>
</div>
<p class="mb-1 small">
<%== erb :status_badge_partial, locals: { status: place.status } %>
<%= place.opening_hours %>
</p>
</a>
<% end %>
<%== pagy_bootstrap_nav(@search_result.paginator) %>
</div>
<div class="col">
<div id="map" class="full"></div>
</div>
</section>

+ 5
- 0
lib/app.rb View File

@@ -123,6 +123,11 @@ module Hours
erb :home
end

get '/search', provides: 'html' do
@search_result = Hours::Projections::SearchQuery.build.handle(params[:q])
erb :search
end

get '/in/:slug', provides: 'html' do
@region = Hours::Projections::RegionQuery.build.handle(
params[:slug],

+ 54
- 0
test/fixtures/vcr_cassettes/bragi_autocomplete_smullers.yml View File

@@ -0,0 +1,54 @@
---
http_interactions:
- request:
method: get
uri: http://localhost:4000/autocomplete?q=Smullers
body:
encoding: US-ASCII
string: ''
headers:
User-Agent:
- Faraday v1.0.0
response:
status:
code: 200
message: OK
headers:
content-length:
- '7932'
connection:
- close
content-type:
- application/json
cache-control:
- max-age=3600
date:
- Mon, 16 Mar 2020 18:11:03 GMT
body:
encoding: UTF-8
string: '{"type":"FeatureCollection","geocoding":{"version":"0.1.0","query":""},"features":[
{"type":"Feature","geometry":{"coordinates":[5.4796854999999995,51.4433638],"type":"Point"},"properties":{"geocoding":{"id":"poi:osm:node:692975604","type":"poi","label":"Smullers","name":"Smullers","postcode":null,"city":null,"citycode":null,"administrative_regions":[],"poi_types":[{"id":"poi_type:amenity:fast_food","name":"Fast-food"}],"properties":[{"key":"amenity","value":"fast_food"},{"key":"level","value":"0"},{"key":"name","value":"Smullers"}],"address":{"id":"addr:5.4798923;51.4432747:22-01","type":"house","label":"Stationsplein
22-01","name":"Stationsplein 22-01","housenumber":"22-01","street":"Stationsplein","postcode":"5611AC","city":null,"citycode":null,"administrative_regions":[]}}}},
{"type":"Feature","geometry":{"coordinates":[4.837769,52.389256],"type":"Point"},"properties":{"geocoding":{"id":"poi:osm:node:1282023633","type":"poi","label":"Smullers","name":"Smullers","postcode":null,"city":null,"citycode":null,"administrative_regions":[],"poi_types":[{"id":"poi_type:amenity:fast_food","name":"Fast-food"}],"properties":[{"key":"amenity","value":"fast_food"},{"key":"layer","value":"1"},{"key":"level","value":"1"},{"key":"name","value":"Smullers"},{"key":"takeaway","value":"yes"}],"address":{"id":"addr:4.8376742;52.3892327:103B","type":"house","label":"Orlyplein
103B","name":"Orlyplein 103B","housenumber":"103B","street":"Orlyplein","postcode":"1043DT","city":null,"citycode":null,"administrative_regions":[]}}}},
{"type":"Feature","geometry":{"coordinates":[4.899452999999999,52.379396],"type":"Point"},"properties":{"geocoding":{"id":"poi:osm:node:1539937895","type":"poi","label":"Smullers","name":"Smullers","postcode":null,"city":null,"citycode":null,"administrative_regions":[],"poi_types":[{"id":"poi_type:amenity:fast_food","name":"Fast-food"}],"properties":[{"key":"amenity","value":"fast_food"},{"key":"fast_food","value":"frites"},{"key":"level","value":"0"},{"key":"name","value":"Smullers"},{"key":"wheelchair","value":"yes"}],"address":{"id":"addr:4.8993813;52.3794034:45E","type":"house","label":"Stationsplein
45E","name":"Stationsplein 45E","housenumber":"45E","street":"Stationsplein","postcode":"1012AB","city":null,"citycode":null,"administrative_regions":[]}}}},
{"type":"Feature","geometry":{"coordinates":[4.482258,52.166436],"type":"Point"},"properties":{"geocoding":{"id":"poi:osm:node:1550278595","type":"poi","label":"Smullers","name":"Smullers","postcode":null,"city":null,"citycode":null,"administrative_regions":[],"poi_types":[{"id":"poi_type:amenity:fast_food","name":"Fast-food"}],"properties":[{"key":"amenity","value":"fast_food"},{"key":"cuisine","value":"fries"},{"key":"name","value":"Smullers"},{"key":"wheelchair","value":"yes"}],"address":{"id":"addr:4.4823144;52.1664861:3C","type":"house","label":"Stationsplein
3C","name":"Stationsplein 3C","housenumber":"3C","street":"Stationsplein","postcode":"2312AJ","city":null,"citycode":null,"administrative_regions":[]}}}},
{"type":"Feature","geometry":{"coordinates":[6.5669284999999995,53.2111502],"type":"Point"},"properties":{"geocoding":{"id":"poi:osm:node:1820935444","type":"poi","label":"Smullers","name":"Smullers","postcode":null,"city":null,"citycode":null,"administrative_regions":[],"poi_types":[{"id":"poi_type:amenity:fast_food","name":"Fast-food"}],"properties":[{"key":"amenity","value":"fast_food"},{"key":"name","value":"Smullers"}],"address":{"id":"addr:6.5669698;53.2111573:12","type":"house","label":"Stationsweg
12","name":"Stationsweg 12","housenumber":"12","street":"Stationsweg","postcode":"9726AC","city":null,"citycode":null,"administrative_regions":[]}}}},
{"type":"Feature","geometry":{"coordinates":[5.8531037999999995,51.8429894],"type":"Point"},"properties":{"geocoding":{"id":"poi:osm:node:2303136888","type":"poi","label":"Smullers","name":"Smullers","postcode":null,"city":null,"citycode":null,"administrative_regions":[],"poi_types":[{"id":"poi_type:amenity:fast_food","name":"Fast-food"}],"properties":[{"key":"amenity","value":"fast_food"},{"key":"name","value":"Smullers"}],"address":{"id":"addr:5.8530919;51.843104:6P","type":"house","label":"Stationsplein
6P","name":"Stationsplein 6P","housenumber":"6P","street":"Stationsplein","postcode":"6512AB","city":null,"citycode":null,"administrative_regions":[]}}}},
{"type":"Feature","geometry":{"coordinates":[4.6684972,51.8074112],"type":"Point"},"properties":{"geocoding":{"id":"poi:osm:node:2312666233","type":"poi","label":"Smullers","name":"Smullers","postcode":null,"city":null,"citycode":null,"administrative_regions":[],"poi_types":[{"id":"poi_type:amenity:fast_food","name":"Fast-food"}],"properties":[{"key":"amenity","value":"fast_food"},{"key":"name","value":"Smullers"}],"address":{"id":"addr:4.668338;51.8075061:1","type":"house","label":"Stationsplein
1","name":"Stationsplein 1","housenumber":"1","street":"Stationsplein","postcode":"3311JV","city":null,"citycode":null,"administrative_regions":[]}}}},
{"type":"Feature","geometry":{"coordinates":[5.1089381,52.089424],"type":"Point"},"properties":{"geocoding":{"id":"poi:osm:node:2449612553","type":"poi","label":"Smullers","name":"Smullers","postcode":"3511CB","city":null,"citycode":null,"administrative_regions":[],"poi_types":[{"id":"poi_type:amenity:fast_food","name":"Fast-food"}],"properties":[{"key":"addr:city","value":"Utrecht"},{"key":"addr:housenumber","value":"7b"},{"key":"addr:postcode","value":"3511CB"},{"key":"addr:street","value":"Stationspassage"},{"key":"amenity","value":"fast_food"},{"key":"layer","value":"2"},{"key":"level","value":"1"},{"key":"name","value":"Smullers"},{"key":"source","value":"BAG"},{"key":"source:date","value":"2016-03-22"},{"key":"toilets:wheelchair","value":"no"},{"key":"wheelchair","value":"yes"}],"address":{"id":"addr:5.1088784;52.0893902:10","type":"house","label":"Stationspassage
10","name":"Stationspassage 10","housenumber":"10","street":"Stationspassage","postcode":"3511CB","city":null,"citycode":null,"administrative_regions":[]}}}},
{"type":"Feature","geometry":{"coordinates":[6.0916635,52.5053706],"type":"Point"},"properties":{"geocoding":{"id":"poi:osm:node:2497603411","type":"poi","label":"Smullers","name":"Smullers","postcode":"8011CW","city":null,"citycode":null,"administrative_regions":[],"poi_types":[{"id":"poi_type:amenity:fast_food","name":"Fast-food"}],"properties":[{"key":"addr:city","value":"Zwolle"},{"key":"addr:housenumber","value":"22"},{"key":"addr:postcode","value":"8011CW"},{"key":"addr:street","value":"Stationsplein"},{"key":"amenity","value":"fast_food"},{"key":"name","value":"Smullers"},{"key":"source","value":"BAG"},{"key":"source:date","value":"2013-09-08"}],"address":{"id":"addr:6.0916966;52.505363:22","type":"house","label":"Stationsplein
22","name":"Stationsplein 22","housenumber":"22","street":"Stationsplein","postcode":"8011CW","city":null,"citycode":null,"administrative_regions":[]}}}},
{"type":"Feature","geometry":{"coordinates":[4.4689977,51.924987599999994],"type":"Point"},"properties":{"geocoding":{"id":"poi:osm:node:2610276000","type":"poi","label":"Smullers","name":"Smullers","postcode":"3013AJ","city":null,"citycode":null,"administrative_regions":[],"poi_types":[{"id":"poi_type:amenity:fast_food","name":"Fast-food"}],"properties":[{"key":"addr:city","value":"Rotterdam"},{"key":"addr:housenumber","value":"8A"},{"key":"addr:postcode","value":"3013AJ"},{"key":"addr:street","value":"Stationsplein"},{"key":"amenity","value":"fast_food"},{"key":"name","value":"Smullers"},{"key":"operator","value":"NS
Stations"},{"key":"source","value":"BAG"},{"key":"source:date","value":"2013-11-26"},{"key":"wheelchair","value":"yes"}],"address":{"id":"addr:4.4689977;51.9249876:8A","type":"house","label":"Stationsplein
8A","name":"Stationsplein 8A","housenumber":"8A","street":"Stationsplein","postcode":"3013AJ","city":null,"citycode":null,"administrative_regions":[]}}}}
]}'
http_version: null
recorded_at: Mon, 16 Mar 2020 18:11:03 GMT
recorded_with: VCR 5.1.0

+ 19
- 0
test/integration/web/searches_places_test.rb View File

@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'test_helper'

describe 'web view places' do
include WebTestHelpers

describe 'GET /search?q=<term>' do
it 'returns search results from bragi' do
VCR.use_cassette(:bragi_autocomplete_smullers) do
visit '/search?q=Smullers'
end

assert_equal 200, page.driver.status_code
assert_selector page, 'h2', text: 'Zoekresultaat voor Smullers'
assert_selector page, 'a.list-group-item', text: 'Smullers'
end
end
end

+ 7
- 1
test/test_helper.rb View File

@@ -2,12 +2,13 @@

require 'minitest/autorun'
require 'database_cleaner'
require 'byebug'
require 'vcr'

require 'hours'
require 'app'

require 'awesome_print'
require 'byebug'
require 'ostruct'

ENV['APP_ENV'] = ENV['RACK_ENV'] = 'test'
@@ -38,6 +39,11 @@ module Minitest
DatabaseCleaner.strategy = :truncation,
{ except: %w[spatial_ref_sys query_addresses] }

VCR.configure do |config|
config.cassette_library_dir = 'test/fixtures/vcr_cassettes'
config.hook_into :faraday
end

before :each do
DatabaseCleaner.start
end

Loading…
Cancel
Save