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

refactor(location search): Photon: restrict via API URL on shop & amenity #808

Merged
merged 2 commits into from
Sep 20, 2024
Merged
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
19 changes: 14 additions & 5 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import constants from '../constants'
const PRICE_UPDATE_FIELDS = ['price', 'price_is_discounted', 'price_without_discount', 'price_per', 'currency', 'date']
const PRICE_CREATE_FIELDS = PRICE_UPDATE_FIELDS.concat(['product_code', 'product_name', 'category_tag', 'labels_tags', 'origins_tags', 'location_osm_id', 'location_osm_type', 'proof_id'])
const PROOF_UPDATE_FIELDS = ['type', 'date', 'currency']
const LOCATION_SEARCH_LIMIT = 10

const OP_DEFAULT_PAGE_SIZE = 20 // 100 slows down the app
const OP_DEFAULT_HEADERS = {
Expand Down Expand Up @@ -231,31 +232,39 @@ export default {
},

openfoodfactsProductSearch(code) {
return fetch(`${constants.OFF_API_URL}/${code}.json`, {
const url = `${constants.OFF_API_URL}/${code}.json`
return fetch(url, {
method: 'GET',
headers: OP_DEFAULT_HEADERS
})
.then((response) => response.json())
},

openstreetmapNominatimSearch(q) {
return fetch(`${constants.OSM_NOMINATIM_SEARCH_URL}?q=${q}&addressdetails=1&format=json&limit=10`, {
const url = `${constants.OSM_NOMINATIM_SEARCH_URL}?q=${q}&addressdetails=1&format=json&limit=${LOCATION_SEARCH_LIMIT}`
return fetch(url, {
method: 'GET',
headers: OP_DEFAULT_HEADERS
})
.then((response) => response.json())
.then((data) => data.filter(l => !constants.NOMINATIM_RESULT_TYPE_EXCLUDE_LIST.includes(l.type)))
},
openstreetmapNominatimLookup(id) {
return fetch(`${constants.OSM_NOMINATIM_LOOKUP_URL}?osm_ids=N${id},W${id},R${id}&addressdetails=1&format=json`, {
const url = `${constants.OSM_NOMINATIM_LOOKUP_URL}?osm_ids=N${id},W${id},R${id}&addressdetails=1&format=json`
return fetch(url, {
method: 'GET',
headers: OP_DEFAULT_HEADERS
})
.then((response) => response.json())
.then((data) => data.filter(l => !constants.NOMINATIM_RESULT_TYPE_EXCLUDE_LIST.includes(l.type)))
},
openstreetmapPhotonSearch(q) {
return fetch(`${constants.OSM_PHOTON_SEARCH_URL}?q=${q}&limit=10`, {
// Photon: restrict the search to shop & amenity
openstreetmapPhotonSearch(q, restrictToShop=true) {
let url = `${constants.OSM_PHOTON_SEARCH_URL}?q=${q}&limit=${LOCATION_SEARCH_LIMIT}`
if (restrictToShop) {
url += '&osm_key=shop&osm_tag=amenity'
}
return fetch(url, {
method: 'GET',
headers: OP_DEFAULT_HEADERS
})
Expand Down
Loading